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

Set-26 C MCQ

1. What is the output of the following code?

include<stdio.h>
int main()
{
char ptr; ptr = “A BCD EFGH”; printf(“%c”,&*ptr);
return 0;
}

a. A
b. A BCD EFGH
c. Some address will be printed
d. Compilation Error

Answer : a


2. What is the output of the following code?

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

a. 5, 5
b. 2, 2
c. 25, 4
d. 5, 2

Answer : d


3. What is the output of the following code?

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

a. 5, 5
b. 2, 2
c. 25, 4
d. 5, 2

Answer : c


4. What is the output of following code?

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

a. 5
b. Garbage Value
c. Compilation Error
d. Segmentation Fault

Answer : a


5. What is the output of the following code?

include<stdio.h>
int main()
{
int i = 97, *ptr = &i;
func(&ptr);
printf(“%d “, *ptr);
return 0;
}
void func(int **ptr)
{
int j = 2;
*ptr = &j;
printf(“%d “, **ptr);
}

a. 2 97
b. 2 2
c. Undefined Behaviour
d. Segmentation Fault

Answer : b


6. What is the output of the following code?

include<stdio.h>
void main()
{
int k = 5;
int *p = &k;
int **m = &p;
**m = 6;
printf(“%d\n”, k);
}

a. 6
b. Compile time error
c. 5
d. Junk

Answer : a


7. What is the output of this C code?

include<stdio.h>
void main()
{
int a[3] = {1, 2, 3};
int *ptr = a;
int *r = &ptr;
printf(“%d”, (**r));
}

a. 1
b. Compile time error
c. Address of a
d. Junk value

Answer : b
C MCQ Set-20 Explanation


8. What is the output of this C code?

include<stdio.h>
void main()
{
int a[3] = {1, 2, 3};
int *p = a;
int **r = &p;
printf(“%p %p”, *r, a);
}

a. Different address is printed
b. 1 2
c. Same address is printed.
d. 1 1

Answer : c
C MCQ Set-20 Explanation


9. What is the output of this C code?

include<stdio.h>
void main()
{
int a[] = {1,2,9,8,6,3,5,7,8,9};
int *p = a + 1;
int *q = a + 6;
printf(“\n%d”, q-p);
}

a. 5
b. 9
c. 6
d. 2

Answer : a


10. What is a dangling pointer in C programming language?

a. If pointer is assigned to more than one variable.
b. If pointer is not defined properly.
c. If pointer is pointing to a memory location from where variable has been deleted.
d. None of above.

Answer : c


Spread the love

Leave a Comment

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