0% found this document useful (0 votes)
37 views4 pages

Mock Questions For TCS NQT

Uploaded by

Rahul Kapoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views4 pages

Mock Questions For TCS NQT

Uploaded by

Rahul Kapoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Function Question

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


#include <stdio.h>
int main()
{
void foo();
printf("1 ");
foo();
}
void foo()
{
printf("2 ");
}
A. 1 2
B. Compile time error
C. 1 2 1 2
D. Depends on the compiler

Answer:A
Explanation: At first main function will execute and give the o/p 1 then the function is called
which give 2 as output.

2. What will be the output of the following C code?


#include <stdio.h>
int main()
{
void foo();
void f()
{
foo();
}
f();
}
void foo()
{
printf("2 ");
}
A. 2 2
B. 2
C. Compile time error
D. Depends on the compiler

Answer: D
Explanation: Even though the answer is 2, this code will compile fine only with gcc. GNU C
supports nesting of functions in C as a language extension whereas standard C compiler
doesn’t.
3. What will be the output of the following C code?
#include <stdio.h>
void m();
void n()
{
m();
}
void main()
{
void m()
{
printf("hi");
}
}
A. Hi
B. Compile time error
C. Nothing
D. Varies
Answer: B
Explanation: Function is nested and is not defined.

3. What will be the output of the following C code?


#include <stdio.h>
void main ()
{
static int x = 3;
x++;
if (x <= 5)
{
printf("hi");
main();
}
}
A. Run time error
B. Hi
C. Infinite hi
D. hi hi
Answer: D
Explanation: At first x=3 will execute then it incremented to 4 and the condition is still
true.

4. Which of the following function declaration is illegal?


a) int 1bhk(int);
b) int 1bhk(int a);
c) int 2bhk(int*, int []);
d) all of the mentioned

Answer: D
Explanation: Unknown Syntax.
5. What is the return-type of the function sqrt()?
a) int
b) float
c) double
d) depends on the data type of the parameter
Answer: c
Explanation: Sqrt() is return double because its range is high to hold value0.

6. What will be the output of the following C 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

Answer: D
Explanation: In given function foo() is not defined correctly.

7. What is the problem in the following C 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

Answer: D
Explanation: Declaration syntax must have to follow datatype var1,var2..;

8. Functions can return structure in C?


A) True
B) False
C) Depends on the compiler
D) Depends on the standard

Answer: A
Explanation: None.

9. What does the given C code do?


double atan2 (double y, double x);
A) The atan2 function returns the arc tangent of x/y
B) The atan2 function returns the arc tangent of x
C) The atan2 function returns the arc tangent of y/x
D) The atan2 function returns the arc tangent of y
Answer: c
Explanation: The atan2 function returns the arc tangent of y/x, in the range [-pi,+pi] radians.

10. Name the function that breaks a floating-point number into a normalized fraction and
an integral power of 2.
A) exp()
B) frexp()
C) Idexp()
D) modf()

Answer: B
Explanation: The frexp() function breaks a floating-point number into a normalized fraction
and an integral power of 2.

You might also like