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 8 of 9.
Waste body said:
1 decade ago
Thanks nilesh.
Cheran said:
1 decade ago
Thanks Nilesh....Good Job
Lucky said:
1 decade ago
ch is character variable then hw would we assign it to 74?
Bijan said:
1 decade ago
Hi sourav,
Typecasting is making a variable of one type, such as an int, act like another type, a char, for one single operation. To typecast something, simply put the type of variable you want the actual variable to act as inside parentheses in front of the actual variable. (char)a will make 'a' function as a char.
#include <iostream>
using namespace std;
int main()
{
cout<< (char)65 <<"\n";
// The (char) is a typecast, telling the computer to interpret the 65 as a
// character, not as a number. It is going to give the character output of
// the equivalent of the number 65 (It should be the letter A for ASCII).
cin.get();
}
Typecasting is making a variable of one type, such as an int, act like another type, a char, for one single operation. To typecast something, simply put the type of variable you want the actual variable to act as inside parentheses in front of the actual variable. (char)a will make 'a' function as a char.
#include <iostream>
using namespace std;
int main()
{
cout<< (char)65 <<"\n";
// The (char) is a typecast, telling the computer to interpret the 65 as a
// character, not as a number. It is going to give the character output of
// the equivalent of the number 65 (It should be the letter A for ASCII).
cin.get();
}
Saurav said:
1 decade ago
What is the difference between int and char typecasting. Please explain.
Aman said:
1 decade ago
Thanks dude.
Gr8 work.
Gr8 work.
Siba said:
1 decade ago
Thanks from bottom of my heart.
Yaminikannan said:
1 decade ago
Thank you nilesh.
Saranya said:
1 decade ago
Thanks nilesh.
Shrinivas Prabhu said:
1 decade ago
Thanks buddy, nice explanation.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers