Tutorials  Articles  Notifications  Login  Signup

Introduction C Programming variables (Set 1) C Programming variables (Set 2) C Programming variable and function declaration (set 3) Pointers in C Pointers (set 2)



Pointers (set 2)



MCQ Problems on pointers in C


1.

What would be output of the following code on Linux machine:

#include<stdio.h>

int main()
{
    int i=15, *j, *k;
    j=&i; // Suppose address of i is 100
    k=j;
    *j++=*k++;
    i++;
    printf("i=%d j=%d  k=%d ", i, j, k);
    return 0;
}

(On Linux Machines, size of pointers are 4 bytes)

A.

i=16 j=102  k=102

B.

i=16 j=104  k=104

C.

i=16 j=100  k=100

D.

None of the options



2.

What would be output of the following program:

#include<stdio.h>

int main()
{
    char name[20] = "HackersFriend";
    char *const x=name;
    *x='h';
    printf("%s", name);
    return 0;
}

 

A.

HackersFriend

B.

hackersfriend

C.

hHackersFriend

D.

HhackersFriend



3.

What would be the output of following on Linux Machine:

#include<stdio.h>

int main()
{
    int ***z, **y, *x, m=8;
    x = &m;
    y = &x;
    z = &y;
    printf("%d %d %d", *x, **y, ***z);
    return 0;
}

(On Linux Machines, size of pointers are 4 bytes)

A.

4 4 4

B.

8 8 8

C.

Garbage values

D.

None of the options





HackerFriend Logo

Join the community of 1 Lakh+ Developers

Create a free account and get access to tutorials, jobs, hackathons, developer events and neatly written articles.


Create a free account