C Programming - Pointers
Exercise : Pointers - Find Output of Program
6.
What will be the output of the program ?
#include<stdio.h>
void fun(void *p);
int i;
int main()
{
void *vptr;
vptr = &i;
fun(vptr);
return 0;
}
void fun(void *p)
{
int **q;
q = (int**)&p;
printf("%d\n", **q);
}
7.
What will be the output of the program ?
#include<stdio.h>
int main()
{
char *str;
str = "%s";
printf(str, "K\n");
return 0;
}
8.
What will be the output of the program ?
#include<stdio.h>
int *check(static int, static int);
int main()
{
int *c;
c = check(10, 20);
printf("%d\n", c);
return 0;
}
int *check(static int i, static int j)
{
int *p, *q;
p = &i;
q = &j;
if(i >= 45)
return (p);
else
return (q);
}
9.
What will be the output of the program if the size of pointer is 4-bytes?
#include<stdio.h>
int main()
{
printf("%d, %d\n", sizeof(NULL), sizeof(""));
return 0;
}
Answer: Option
Explanation:
In TurboC, the output will be 2, 1 because the size of the pointer is 2 bytes in 16-bit platform.
But in Linux, the output will be 4, 1 because the size of the pointer is 4 bytes.
This difference is due to the platform dependency of C compiler.
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;
}
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers