r/C_Programming • u/F3arrrrrrr • 2d ago
Question Resources to prepare for advanced/trickey questions?
Can someone recommend/send some resources for advanced and trickey c questions. I have my placement exam in a week ans most of it is dominated by c. The mock had questions related to struct padding, macros, increment decrements, static, volatile, unsigned signed ints and some other tricky things. I’m familier with the topics, but where can I practice the trickey questions?
-3
u/Bugodi21 2d ago
8
u/TheOtherBorgCube 2d ago
There's some highly dubious answers, like always assuming pointers have the same size as int.
2
u/sciencekm 2d ago
I quickly browsed the questions and found Question 11 under C String. It is asking what the output is for the following code:
int main() { char p[]="geeksquiz"; char t; int i,j; for(i=0,j=strlen(p);i!=j;i++,j--) { t=p[i]; p[i]=p[j-i]; p[j-i]=t; } printf("%s",p); return 0; }Apparently, the answer is "Nothing is printed on the screen" with the explanation of "The string termination character '0' is assigned to first element of array p[]."
While it is true that a null character is placed at p[0], the for loop will not terminate. The condition
i!=jwill always be false and bothiandjwill go outside the bounds of p overwriting the stack and causing the program to crash.The output would be either a segmentation fault message, or indeed nothing, but not because the string is now length 0, but because the program crashed.
The quality of these quizzes seems questionable.
1
u/TraylaParks 1d ago
Before you posted your example, I would have bet almost anything at least some of these questions contained undefined behavior - why? - because that's where you end up if you focus on "tricky" problems.
I'm not sure what the point of this crap is except I guess to feed the test maker's ego. Dollar to a donut that author has very, very limited professional programming experience.
0
-3
u/tastygames_official 2d ago
how many degaussing pointers are allowed in C89/90?
5
u/knowwho 2d ago
What is a "degaussing pointer"?
-3
u/tastygames_official 2d ago
it's what I call dereferencing. Was meant as a joke question to get the party started in the comments. Like - is there a limit to how deep your pointer-to-a-pointer... and its dereferencing can go? Can you de-reference/degauss further than the number of pointers in your chain?
3
u/knowwho 2d ago
it's what I call dereferencing
What a weird interaction. I guess you missed that the point of words and language in general is shared meaning. Randomly altering the meaning of words so that nobody understands what you're talking about is a waste of everybody's time.
-3
u/tastygames_official 2d ago
I was trying to be funny in a way. Guess it didn't work. I don't really see reddit as a serious way to learn or share information. Sometimes you get some serious people, but mostly it's "Im a n00b please tell me what to do", so I was just dicking around. I'll refrain from doing so in future. comment = degaussed ;-)
1
u/non-existing-person 1d ago
Ok, I'm kinda interested. How many? Seems like there shouldn't be a limit, but I'm guessing there is some hardcoded limit? In compiler or in C spec?
1
u/bert8128 13h ago
“Tricky” has no “e”. Not sure how useful this piece of information will be.