Find Output Of Program

Question 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
Answer : Option C

Question 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). No output
C). K
D). %s
Answer : Option C

Question 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
Answer : Option D

Question 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
Answer : Option C

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.


Question 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
Answer : Option D