C MCQ Set-19 : Multiple Choice Questions in C Set-19

Set-26 C MCQ

  1. In the following code what is ‘C’?

typedef char* charp;
const charp C;

a. C is a constant.
b. C is a character constant.
c. C is character type.
d. None of the above.

Answer : a


  1. The size of a void pointer in 16-bit system is __?

a. 1 Byte
b. 2 Bytes
c. 4 Bytes
d. 8 Bytes

Answer : b


  1. Which of the following does not initialize ptr to null
    (assuming variable declaration of ‘var’ as int var=0)?

a. int *p = &var – &var;
b. int *p = var – var;
c. int *p = &var;
d. int *ptr=NULL;

Answer : c


  1. What is (void*)0?

a. Representation of void pointer
b. Representation of null pointer
c. Compilation error
d. None of them

Answer : b


  1. What is the output of following program?

#include<stdio.h>
int main()
{
int *ptr, var=5;
ptr = &var;
*ptr += 1;
printf(“%d, %d”, *ptr, var);
return 0;
}

a. 5, 5
b. 6, 5
c. 5, 6
d. 6, 6

Answer : d


  1. What the following, instruction tells?

    const int *ptr;

a. We cannot change the pointer ptr itself.
b. We cannot change the value pointed by ptr.
c. Both (a) and (b).
d. We can change the pointer as well as the value pointed by it.

Answer : b


  1. What does the following declaration mean?

    int (*ptr)[10];

a. ptr is 1-D array of size 10, of pointers to integers.
b. ptr is a pointer to a 10 elements integer array.
c. The same as int *ptr[10]
d. None of these.

Answer : b
C MCQ Set-19 Explanation


  1. What will be the output of the following program?

#include<stdio.h>
int main()
{
int var = 5;
void ptr = &var; printf(“%d\n”, (int)ptr);
return 0;
}

a. 5
b. Runtime Error
c. Compilation Error
d. Undefined behavior

Answer : c
C MCQ Set-19 Explanation


  1. What will be the output of the following program code?

#include<stdio.h>
int main()
{
int a = 15;
void *ptr = &a;
printf(“%f\n”, *(float *)ptr);
return 0;
}

a. 65624
b. 0.000000
c. 15
d. Error

Answer : b


  1. What will be the output of the following code?

#include<stdio.h>
int main()
{
int i = 5;
void *ptr = &i;
printf(“%d\n”, *(int *)ptr);
return 0;
}

a. 5
b. Garbage value
c. Compilation Error
d. None of these.

Answer : a


Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *