C Programming - Pointers - Discussion

Discussion Forum : Pointers - Find Output of Program (Q.No. 14)
14.
What will be the output of the program ?
#include<stdio.h>

int main()
{
    char *str;
    str = "%d\n";
    str++;
    str++;
    printf(str-2, 300);
    return 0;
}
No output
30
3
300
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
43 comments Page 5 of 5.

Sunitha said:   1 decade ago
Thank you very much archana.

Archana said:   2 decades ago
Twice str is incremented n then when we do str-2, it is again pointing to starting position. So str contains "%d\n".

So printf statement would be like printf("%d\n",300);

Hence output will be 300.

Vijay said:   2 decades ago
Hi guys,

Can anyone give the explanation for this problem?


Post your comments here:

Your comments will be displayed after verification.