just started programming in C a few days ago and I have a quick question for some clarification on a method I found here on Stack that helped me solve a problem. So we have to grab the last three letters of two ID's both of which belong to a student struct. The solution I went with was creating a char sub1[4] and char sub2[4] and then doing a strncpy(sub1, &student1.id[student1.len - 3], 3) for sub1 and sub2. I am not entirely sure what the ampersand is doing here so if anyone can clarify that would be fantastic. My other option was to create a pointer char to each ID and increment it to start at the last 3 and essentially do the same thing I did before. Using the & saves me doing the pointer arithmetic so naturally I prefer to leave it as such, but I'd like to know exactly why it works. Thanks in advance!
https://stackoverflow.com/questions/66810093/substrings-in-c-clarification March 26, 2021 at 10:06AM
没有评论:
发表评论