Find Output Of Program

Question 1 :

What will be the output of the program ?

#include < stdio.h >
int main()
{
    static char *s[] = {"black", "white", "pink", "violet"};
    char **ptr[] = {s+3, s+2, s+1, s}, ***p;
    p = ptr;
    ++p;
    printf("%s", **p+1);
    return 0;
}


A). ink
B). ack
C). ite
D). let
Answer : Option A

Question 2 :

What will be the output of the program ?

#include < stdio.h >
int main()
{
    int i=3, *j, k;
    j = &i;
    printf("%d\n", i**j*i+*j);
    return 0;
}


A). 30
B). 27
C). 9
D). 3
Answer : Option A

Question 3 :

What will be the output of the program ?

#include < stdio.h >
int main()
{
    int x=30, *y, *z;
    y=&x; /* Assume address of x is 500 and integer is 4 byte size */
    z=y;
    *y++=*z++;
    x++;
    printf("x=%d, y=%d, z=%d\n", x, y, z);
    return 0;
}


A). x=31, y=502, z=502
B). x=31, y=500, z=500
C). x=31, y=498, z=498
D). x=31, y=504, z=504
Answer : Option D

Question 4 :

What will be the output of the program ?

#include < stdio.h >
int main()
{
    char str[20] = "Hello";
    char *const p=str;
    *p='M';
    printf("%s\n", str);
    return 0;
}


A). Mello
B). Hello
C). HMello
D). MHello
Answer : Option A

Question 5 :

What will be the output of the program If the integer is 4bytes long?

#include < stdio.h >
int main()
{
    int ***r, **q, *p, i=8;
    p = &i;
    q = &p;
    r = &q;
    printf("%d, %d, %d\n", *p, **q, ***r);
    return 0;
}


A). 8, 8, 8
B). 4000, 4002, 4004
C). 4000, 4004, 4008
D). 4000, 4008, 4016
Answer : Option A

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

Question 11 :

What will be the output of the program?

#include < stdio.h >
int main()
{
    int arr[2][2][2] = {10, 2, 3, 4, 5, 6, 7, 8};
    int *p, *q;
    p = &arr[1][1][1];
    q = (int*) arr;
    printf("%d, %d\n", *p, *q);
    return 0;
}


A). 8, 10
B). 10, 2
C). 8, 1
D). Garbage values
Answer : Option A

Question 12 :

What will be the output of the program assuming that the array begins at the location 1002 and size of an integer is 4 bytes?

#include < stdio.h >
int main()
{
    int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
    printf("%u, %u, %u\n", a[0]+1, *(a[0]+1), *(*(a+0)+1));
    return 0;
}


A). 448, 4, 4
B). 520, 2, 2
C). 1006, 2, 2
D). Error
Answer : Option C

Question 13 :

13. What will be the output of the program?

#include < stdio.h >
int main()
{
    int arr[3] = {2, 3, 4};
    char *p;
    p = arr;
    p = (char*)((int*)(p));
    printf("%d, ", *p);
    p = (int*)(p+1);
    printf("%d", *p);
    return 0;
}


A). 2, 3
B). 2, 0
C). 2, Garbage value
D). 0, 0
Answer : Option B

Question 14 :

What will be the output of the program ?

#include < stdio.h >
int main()
{
    char *str;
    str = "%d\n";
    str++;
    str++;
    printf(str-2, 300);
    return 0;
}


A). No output
B). 30
C). 3
D). 300
Answer : Option D

Question 15 :

What will be the output of the program ?

#include < stdio.h >
int main()
{
    printf("%c\n", 7["IndiaPAR"]);
    return 0;
}


A). Error: in printf
B). Nothing will print
C). print "R" of IndiaPAR
D). print "7"
Answer : Option C

Question 16 :

What will be the output of the program ?

#include < stdio.h >
int main()
{
    char str[] = "peace";
    char *s = str;
    printf("%s\n", s++ +3);
    return 0;
}


A). peace
B). eace
C). ace
D). ce
Answer : Option D

Question 17 :

What will be the output of the program ?

#include < stdio.h >
int main()
{
    char *p;
    p="hello";
    printf("%s\n", *&*&p);
    return 0;
}


A). llo
B). hello
C). ello
D). h
Answer : Option B

Question 18 :

What will be the output of the program assuming that the array begins at location 1002?

#include < stdio.h >
int main()
{
    int a[2][3][4] = { {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 2}, 
                       {2, 1, 4, 7, 6, 7, 8, 9, 0, 0, 0, 0} };
    printf("%u, %u, %u, %d\n", a, *a, **a, ***a);
    return 0;
}


A). 1002, 2004, 4008, 2
B). 2004, 4008, 8016, 1
C). 1002, 1002, 1002, 1
D). Error
Answer : Option C

Question 19 :

What will be the output of the program ?

#include < stdio.h >
power(int**);
int main()
{
    int a=5, *aa; /* Address of 'a' is 1000 */
    aa = &a;
    a = power(&aa);
    printf("%d\n", a);
    return 0;
}
power(int **ptr)
{
    int b;
    b = **ptr***ptr;
    return (b);
}


A). 5
B). 25
C). 125
D). Garbage value
Answer : Option B

Question 20 :

What will be the output of the program ?

#include < stdio.h >
int main()
{
    char str1[] = "India";
    char str2[] = "PAR";
    char *s1 = str1, *s2=str2;
    while(*s1++ = *s2++)
        printf("%s", str1);

    printf("\n");
    return 0;
}


A). IndiaPAR
B). PndiaPAdiaPARia
C). India
D). (null)
Answer : Option B

Question 21 :

What will be the output of the program ?

#include < stdio.h >
#include < string.h >
int main()
{
    int i, n;
    char *x="Alice";
    n = strlen(x);
    *x = x[n];
    for(i=0; i<=n; i++)
    {
        printf("%s ", x);
        x++;
    }
    printf("\n", x);
    return 0;
}


A). Alice
B). ecilA
C). Alice lice ice ce e
D). lice ice ce e
Answer : Option D

Explanation :

If you compile and execute this program in windows platform with Turbo C, it will give "lice ice ce e".

It may give different output in other platforms (depends upon compiler and machine). The online C compiler given in this site will give the Option C as output (it runs on Linux platform).


Question 22 :

What will be the output of the program ?

#include < stdio.h >
int main()
{
    int i, a[] = {2, 4, 6, 8, 10};
    change(a, 5);
    for(i=0; i<=4; i++)
        printf("%d, ", a[i]);
    return 0;
}
void change(int *b, int n)
{
    int i;
    for(i=0; i < n; i++)
        *(b+1) = *(b+i)+5;
}


A). 7, 9, 11, 13, 15
B). 2, 15, 6, 8, 10
C). 2 4 6 8 10
D). 3, 1, -1, -3, -5
Answer : Option B

Question 23 :

If the size of integer is 4bytes, What will be the output of the program?

#include < stdio.h >

int main()
{
    int arr[] = {12, 13, 14, 15, 16};
    printf("%d, %d, %d\n", sizeof(arr), sizeof(*arr), sizeof(arr[0]));
    return 0;
}


A). 10, 2, 4
B). 20, 4, 4
C). 16, 2, 2
D). 20, 2, 2
Answer : Option B