QUIZ-4 OF C PROGRAMMING LANGUAGE

Quiz-4 of c programming language
Quiz-4 of c programming language

QUIZ-4 OF C PROGRAMMING LANGUAGE

Q 1 – What is the output of the following program?

#include<stdio.h>

main()

{

int x = 3;

x += 2;

x =+ 2;

printf(“%d”, x);

}

A – 2

B – 5

C – 7

D – Compile error

Q 2 – The equivalent pointer expression by using the array element a[i][j][k][2],

A – ((((a+m)+n)+o)+p)

B – *(*(*(*(a+i)+j)+k)+2)

C – *( (((a+m)+n)+o+p)

D – *( ((a+m)+n+o+p)

Q 3 – In the given below code, the function fopen()uses “r” to open the file “source.txt” in binary mode for which purpose?

#include<stdio.h> int main (){   FILE *fp;      fp = fopen(“source.txt”, “r”);   return 0;}

A – For reading

B – For reading and writing

C – For creating a new file “source.txt” for reading

D – For creating a new file “source.txt” for writing

Q 4 – What will be the output of the following program?

#include<stdio.h>

int main()

{

const int x = 5;

const int *ptrx;

ptrx = &x;

*ptrx = 10;

printf(“%d\n”, x);

return 0;

}

A – 10

B – 20

C – 0

D – The program will return error

Q 5 – In the given below code, what will be the value of a variable x?

#include<stdio.h>

int main()

{

int y = 100;

const int x = y;

printf(“%d\n”, x);

return 0;

}

A – 100

B – 0

C – Print x

D – Return Error

Q 6 – What is the output of the following program?

#include<stdio.h>

main()

{

enum { india, is=7, GREAT };

printf(“%d %d”, india, GREAT);

}

A – 0 1.

B – 0 2

C – 0 8

D – Compile error

Q 7 – What is the output of the following program?

#include<stdio.h>

main()

{

struct { int x;} var = {5}, *p = &var;

printf(“%d %d %d”,var.x,p->x,(*p).x);

}

A – 5 5 5

B – 5 5 garbage value

C – 5 5 0

D – Compile error

Q 8 – What is the output of the following program?

#include<stdio.h>

main()

{

int a[3] = {2,1};

printf(“%d”, a[a[1]]);

}

A – 0

B – 1

C – 2

D – 3

Q 9 – What is the output of the following program?

#include<stdio.h>

main()

{

}

A – No output

B – Garbage

C – Compile error

D – Runtime error

Q 10 – What actually get pass when you pass an array as a function argument?

A – First value of elements in array

B – Base address of the array

C – All value of element in array

D – Address of the last element of array

ANSWER WITH EXPLAINATION

1)A

Explanation

+ in unary form is dummy operator, therefore ‘x’ is overwritten with the value +2 finally.

2)B

Explanation

If, the array element is a[i][j] = *(*(a+i)+j)

If, the array element is a[i][j][k]= *(*(*(a+i)+j)+k)

3)A

Explanation

To open a file in C programming, we can use library function fopen(). In the given above code, fopen() function is opening a file “source.txt” for reading. Here, “r” stands for reading. If, fopen() function does not find any file for reading, returns NULL

#include<stdio.h> int main (){   FILE *fp;      fp = fopen(“source.txt”, “r”);   return 0;}

4)D

Explanation

The above program will return error

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

5)A

Explanation

Although, integer y = 100; and constant integer x is equal to y. here in the given above program we have to print the x value, so that it will be 100.

6)C

Explanation

0 8, enums gives the sequence starting with 0. If assigned with a value the sequence continues from the assigned value.

7)A

Explanation

5 5 5, the two possible ways of accessing structure elements using pointer is by using -> (arrow operator) OR *.

8)B

Explaination

1, The inner indirection evaluates to 1, and the value at index 1 for outer indirection is 1.

9)A

Explaination

It is valid to have main() function empty, therefore producing no displayable output.

10)B

Explanation

By passing the name of an array as a function argument; the name contains the base address of an array and the base address (array value) get updated in the main function.

another related quiz of programming click here :

https://www.soluversity.in/quiz-c

You may also like...

Leave a Reply

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