Computer StudyMCQ Computer ScienceQuiz Computer ScienceUGC NET

C Programming Questions and Answers – Functions Returning Non-integers

C Programming Questions and Answers – Functions Returning Non-integers

 

1.What is the return-type of the function sqrt()

a) int

b) float

c) double

d) Depends on the data type of the parameter

View Answer

Answer:c

 

2.Which of the following function declaration is illegal?

a) double func();

int main(){}

double func(){}

b) double func(){};

int main(){}

c) int main()

{

double func();

}

double func(){//statements}

d) None of the mentioned

View Answer

Answer:d

 

3.What is the output of this code having void return-type function?

 

#include <stdio.h>

void foo()

{

return 1;

}

void main()

{

int x = 0;

x = foo();

printf(“%d”, x);

}

a) 1

b) 0

c) Runtime error

d) Compile time error

View Answer

Answer:d

 

4.What will be the data type returned for the following function?

 

#include <stdio.h>

int func()

{

return (double)(char)5.0;

}

a) char

b) int

c) double

d) multiple type-casting in return is illegal

View Answer

Answer:b

 

 

5.What is the problem in the following declarations?

int func(int);

double func(int);

int func(float);

a) A function with same name cannot have different signatures

b) A function with same name cannot have different return types

c) A function with same name cannot have different number of parameters

d) All of the mentioned

View Answer

Answer:d

 

6.The output of the code below is

 

#include <stdio.h>

void main()

{

int k = m();

printf(“%d”, k);

}

void m()

{

printf(“hello”);

}

a) hello 5

b) Error

c) Nothing

d) Junk value

View Answer

Answer:a

 

7.The output of the code below is

#include <stdio.h>

int *m()

{

int *p = 5;

return p;

}

void main()

{

int *k = m();

printf(“%d”, k);

}

a) 5

b) Junk value

c) 0

d) Error

View Answer

Answer:a

 

8.The output of the code below is

 

#include <stdio.h>

int *m();

void main()

{

int *k = m();

printf(“hello “);

printf(“%d”, k[0]);

}

int *m()

{

int a[2] = {5, 8};

return a;

}

a) hello 5 8

b) hello 5

c) hello followed by garbage value

d) Compilation error

View Answer

Answer:c

 

9.The output of the code below is

#include <stdio.h>

int *m();

void main()

{

int k = m();

printf(“%d”, k);

}

int *m()

{

int a[2] = {5, 8};

return a;

}

a) 5

b) 8

c) Nothing

d) Varies

View Answer

Answer:d

 

10.The output of the code below is

 

#include <stdio.h>

void m(int k)

{

printf(“hi”);

}

void m(double k)

{

printf(“hello”);

}

void main()

{

m(3);

}

a) hi

b) hello

c) Compile time error

d) Nothing

View Answer

Answer:c

 

11.What is the default return type if it is not specified in function definition?

a) void

b) int

c) double

d) short int

View Answer

Answer:b

 

12.What is the output of this C code?

 

#include <stdio.h>

int foo();

int main()

{

int i = foo();

}

foo()

{

printf(“2 “);

return 2;

}

a) 2

b) Compile time error

c) Depends on the compiler

d) Depends on the standard

View Answer

Answer:a

 

13.What is the output of this C code?

 

#include <stdio.h>

double foo();

int main()

{

foo();

return 0;

}

foo()

{

printf(“2 “);

return 2;

}

a) 2

b) Compile time error

c) Depends on the compiler

d) Depends on the standard

View Answer

Answer:b

 

14.functions can return structure in c?

a) true

b) false

c) Depends on the compiler

d) Depends on the standard

View Answer

Answer:a

15.functions can return enumeration constants in c?

a) true

b) false

c) depends on the compiler

d) depends on the standard

View Answer

Answer:a

 

16.What is the output of code given below?

 

#include <stdio.h>

enum m{JAN, FEB, MAR};

enum m foo();

int main()

{

enum m i = foo();

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

}

int  foo()

{

return JAN;

}

a) Compile time error

b) 0

c) Depends on the compiler

d) Depends on the standard

 

View Answer

Answer:a

Related Articles

Leave a Reply

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

Back to top button