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;
}
Discussion:
43 comments Page 3 of 5.
Jasmin said:
1 decade ago
Can any body explain what happened to printf (str-2, 300) why only 300 is answer ? Why the value of str-2 is not printed. ?
Gunjan said:
1 decade ago
What will be the output char ch=300;?
As it is unsigned it exceeds the range, what is the answer and why please explain.
As it is unsigned it exceeds the range, what is the answer and why please explain.
Yashwanth P said:
10 years ago
@Nejat.
It's just an assumption. The memory location is allocated randomly by the CPU. It can be any number.
It's just an assumption. The memory location is allocated randomly by the CPU. It can be any number.
Mitali said:
1 decade ago
But here the value of str is not replaced by the value enclosed in double quote. So how is this possible?
Fanzy said:
1 decade ago
Pointers are always incremented by 2 byte. Then how it is possible? can anyone explain this please?
Krishna mohan said:
1 decade ago
Here str is char type & how we can assign it to integer type i.e: %d without any conversion.
Abi said:
1 decade ago
Hi everyone!
Please explain, how come char ptr gives an integer as result without typecasting?
Please explain, how come char ptr gives an integer as result without typecasting?
Alok Kumar said:
1 decade ago
char *ch;
ch="%s\n";
ch++;
ch++;
printf(ch-2,300);
Please explain it.
ch="%s\n";
ch++;
ch++;
printf(ch-2,300);
Please explain it.
Suresh said:
1 decade ago
Thank you sohan lal mits. There is clearance in your explanation. Thanks a lot.
Rishu said:
8 years ago
I think its wrong because we can't increment a string constant pointer.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers