Comments and Discussions
|
|
 |
|
 |
i not reffer all this things
|
|
|
|
 |
|
 |
If someone asked me these for an interview, I'd probably keep my distance from the company. (This is unless they pay me a ton of money )
|
|
|
|
 |
|
 |
On the line that starts with "x=", x is modified twice. The standard says this generates undefined behavior. Same thing for the line that starts with "y=".
|
|
|
|
 |
|
 |
For the same reason above.
|
|
|
|
 |
|
 |
Is that one right?
"If only one person knows the truth, it is still the truth." - Mahatma Gandhi Web - Blog - RSS
|
|
|
|
 |
|
 |
Yes, because you are not passing in a reference to the values being swapped. The only values being swapped are internal to the swap2() function. The values at main are not swapped by swap2().
|
|
|
|
 |
|
 |
Hi,
I think the first example results in an infinite loop that in the end crashes the application
main()
{
char *p1=“name”;
char *p2;
p2=(char*)malloc(20);
memset (p2, 0, 20);
while(*p2++ = *p1++);
printf(“%s\n”,p2);
}
|
|
|
|
 |
|
 |
Nope - no infinite loop there. It'll exit the loop on the 5th iteration because *p1 will be NULL.
|
|
|
|
 |
|
 |
Nishant is right...
empty string would be printed out..
|
|
|
|
 |
|
 |
uppps, you are right. Something new to learn.
By the way, the same snippet modifies the pointer returned by malloc so when you call free to release the memory with that pointer ... It would be better to use a temporary pointer. If the person interviewed points out this, he/she gets extra points?
|
|
|
|
 |
|
 |
hmmmmmmm... point noted...
|
|
|
|
 |
|
|
General
News
Suggestion
Question
Bug
Answer
Joke
Rant
Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.