Pointers - Find Output of Program Multiple Questions and Answers.
Exercise Questions ::
Pointers
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);
}
A. Error: cannot convert from void** to int** B. Garbage value C. 0 D. No output
View Answer
Discuss forum
Workplace
Report
Published by:Michael Daani
7. What will be the output of the program ?
#include<stdio.h>
int main()
{
char *str;
str = "%s" ;
printf(str, "K\n" );
return 0 ;
}
A. Error B. K C. %S D. No output
View Answer
Discuss forum
Workplace
Report
Published by:Michael Daani
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);
}
A. 10 B. 20 C. Error: Non portable pointer conversion D. Error: cannot use static for function parameters
View Answer
Discuss forum
Workplace
Report
Published by:Michael Daani
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 ;
}
A. 2, 1 B. 2, 2 C. 4, 1 D. 4, 2
View Answer
Discuss forum
Workplace
Report
Answer: Option C
Explanation:
1. In TurboC, the output will be 2, 1 because the size of the pointer is 2 bytes in 16-bit platform. 2. But in Linux, the output will be 4, 1 because the size of the pointer is 4 bytes. 3. This difference is due to the platform dependency of C compiler.
See More Information
Tutorial Link:
Published by:Michael Daani
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 ;
}
A. JCK B. J65K C. JAK D. JACK
View Answer
Discuss forum
Workplace
Report
Published by:Michael Daani
« »