C Programming - Pointers - Discussion
Discussion Forum : Pointers - Find Output of Program (Q.No. 10)
10.
What will be the output of the program ?
#include<stdio.h>
int main()
{
void *vp;
char ch=74, *cp="JACK";
int j=65;
vp=&ch;
printf("%c", *(char*)vp);
vp=&j;
printf("%c", *(int*)vp);
vp=cp;
printf("%s", (char*)vp+2);
return 0;
}
Discussion:
84 comments Page 5 of 9.
Manasa said:
1 decade ago
Why we have to write printf("%c", *(int*)vp); why not printf("%c",vp); if you don't mind, please explain?
Parveen said:
1 decade ago
@Manasa.
Because vp is void pointer. When we use void pointer for any data type then we have to typecast that void pointer with the datatype of the variable whose address is stored into that void pointer.
Because vp is void pointer. When we use void pointer for any data type then we have to typecast that void pointer with the datatype of the variable whose address is stored into that void pointer.
Saurabh said:
10 years ago
How to convert those numbers in ASCII values?
Prashanth said:
10 years ago
Hi,
Can anybody say, how you are telling ASCII values like 74=j and 65=a old tel me.
Can anybody say, how you are telling ASCII values like 74=j and 65=a old tel me.
Siya said:
9 years ago
Good explanation. Thank you @Nilesh.
Ponraj said:
9 years ago
@Nilesh.
I understand this with the help of your explanation. Thank you.
I understand this with the help of your explanation. Thank you.
Akash said:
9 years ago
@Nilesh.
Thank you very mush. Your explanation is clear.
Thank you very mush. Your explanation is clear.
Neel Purohit said:
9 years ago
@Nilesh.
Thank you for the brilliant answer and simple explanation.
Thank you for the brilliant answer and simple explanation.
Shwetha said:
9 years ago
Thanks a lot, @Nilesh. Your method is simple, clear and seemed easy :).
Deepak said:
9 years ago
Thank you all, it is very useful.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers