Computer StudyMCQ Computer ScienceQuiz Computer ScienceUGC NET

C Programming Questions and Answers – Complicated Declarations 

C Programming Questions and Answers – Complicated Declarations

 

1.What is the output of this C code?

 

#include <stdio.h>

void main()

{

struct student

{

int no;

char name[20];

};

struct student s;

no = 8;

printf(“%d”, no);

}

a) Nothing

b) Compile time error

c) Junk

d) 8

View Answer

 

Answer:b

2.What is the output of this C code?

 

#include <stdio.h>

struct student

{

int no;

char name[20];

};

void main()

{

struct student s;

s.no = 8;

printf(“hello”);

}

a) Run time error

b) Nothing

c) hello

d) Varies

View Answer

Answer:c   

3.What is the output of this C code?

 

#include <stdio.h>

struct student

{

int no = 5;

char name[20];

};

void main()

{

struct student s;

s.no = 8;

printf(“hello”);

}

a) Nothing

b) Compile time error

c) hello

d) Varies

View Answer

 

Answer:b

4.What is the output of this C code?

 

#include <stdio.h>

struct student

{

int no;

char name[20];

};

void main()

{

student s;

s.name = “hello”;

printf(“hello”);

}

a) Nothing

b) hello

c) Compile time error

d) Varies

View Answer

 

Answer:c

5.What is the output of this C code?

 

#include <stdio.h>

void main()

{

struct student

{

int no;

char name[20];

};

struct student s;

s.no = 8;

printf(“%s”, s.name);

}

a) Nothing

b) Compile time error

c) Junk

d) 8

View Answer

Answer:c 

 

6.What is the output of this C code?

 

#include <stdio.h>

struct student

{

int no;

char name[20];

};

struct student s;

void main()

{

s.no = 8;

printf(“%s”, s.name);

}

a) Nothing

b) Compile time error

c) Junk

d) 8

View Answer

 

Answer:a  

7.What is the output of this C code?

 

#include <stdio.h>

int main()

{

int *((*x)())[2];

x();

printf(“after x\n”);

}

int *((*x)())[2]

{

int **str;

str = (int*)malloc(sizeof(int)* 2);

return str;

}

a) Compile time error

b) Undefined behaviour

c) After x

d) None of the mentioned

View Answer

 

Answer:a

8.What is the output of this C code?

 

#include <stdio.h>

void (*(f)())(int, float);

void (*(*x)())(int, float) = f;

void ((*y)(int, float));

void foo(int i, float f);

int main()

{

y = x();

y(1, 2);

}

void (*(f)())(int, float)

{

return foo;

}

void foo(int i, float f)

{

printf(“%d %f\n”, i, f);

}

a) 1 2.000000

b) 1 2

c) Compile time error

d) Segmentation fault/code crash

View Answer

 

Answer:a  

9.What does this declaration say?

int (*(*y)())[2];

a) y is pointer to the function which returns pointer to integer array

b) y is pointer to the function which returns array of pointers

c) y is function which returns function pointer which in turn returns pointer to integer array

d) y is function which returns array of integers

View Answer

 

Answer:a  

10.What is the output of this C code?

 

#include <stdio.h>

void (*(f)())(int, float);

typedef void (*(*x)())(int, float);

void foo(int i, float f);

int main()

{

x = f;

x();

}

void (*(f)())(int, float)

{

return foo;

}

void foo(int i, float f)

{

printf(“%d %f\n”, i, f);

}

a) Compile time error

b) Undefined behaviour

c) 1 2.000000

d) Nothing

View Answer

 

Answer:a 

11.What is the output of this C code?

 

#include <stdio.h>

void (*(f)())(int, float);

typedef void (*(*x)())(int, float);

void foo(int i, float f);

int main()

{

x p = f;

p();

}

void (*(f)())(int, float)

{

return foo;

}

void foo(int i, float f)

{

printf(“%d %f\n”, i, f);

}

a) Compile time error

b) Undefined behaviour

c) 1 2.000000

d) Nothing

View Answer

 

Answer:d

12.Read the following expression?

void (*ptr)(int);

a) ptr is pointer to int that converts its type to void

b) ptr is pointer to function passing int returning void

c) ptr is pointer to void that converts its type to int

d) ptr is pointer to function passing void returning int

View Answer

 

Answer:b 

13.Which of the following expression is true for the following?

ptr is array with 3 elements of pointer to function returning pointer of int

a) int **ptr[3]();

b) int *(*ptr[3])();

c) int (*(*ptr[3])());

d) None of the mentioned

View Answer

 

Answer:b

14.What do the following declaration denote?

int **ptr;

a) ptr is a function pointer that returns pointer to int type

b) ptr is a pointer to an int pointer

c) ptr is a pointer to pointer to type int

d) None of the mentioned

View Answer

 

Answer:b

15.What do the following declaration denote?

char *str[5];

a) str is an array of 5 element pointer to type char

b) str is a pointer to an array of 5 elements

c) str is a function pointer of 5 elements returning char

d) None of the mentioned

View Answer

 

Answer:a

16.Comment on the following declaration?

int (*ptr)(); // i)

char *ptr[]; // ii)

a) Both i) and ii) and cannot exist due to same name

b) i) is legal, ii) is illegal

c) i) is illegal, ii) is legal

d) Both i) and ii) will work legal and flawlessly

View Answer

 

Answer:d 

17.What is the output of this C code?

 

#include <stdio.h>

struct student

{

int no;

char name[20];

}

void main()

{

struct student s;

s.no = 8;

printf(“hello”);

}

a) Compile time error

b) Nothing

c) hello

d) Varies

View Answer

 

Answer:a

18.What is the output of this C code?

 

#include <stdio.h>

struct student

{

int no = 5;

char name[20];

};

void main()

{

struct student s;

s.no = 8;

printf(“hello”);

}

a) Nothing

b) Compile time error

c) hello

d) Varies

View Answer

 

Answer:b

19.What is the output of this C code?

 

#include <stdio.h>

struct student

{

int no;

char name[20];

};

void main()

{

student s;

s.no = 8;

printf(“hello”);

}

a) Nothing

b) hello

c) Compile time error

d) Varies

View Answer

 

Answer:c

20.What is the output of this C code?

 

#include <stdio.h>

void main()

{

struct student

{

int no;

char name[20];

};

struct student s;

s.no = 8;

printf(“%d”, s.no);

}

a) Nothing

b) Compile time error

c) Junk

d) 8

View Answer

 

Answer:d

21.Is the below declaration legal?

int* ((*x)())[2];

a) true

b) false

c) Undefined behaviour

d) Depends on the standard

View Answer

Related Articles

Leave a Reply

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

Check Also
Close
Back to top button