TCS Functions Questions with Solutions

1. What is the output of this C code?
#include
void main()
{
m();
void m()
{
printf(“SimpleWay2Code”);
}
}
a) SimpleWay2Code
b) Compile time error
c) Nothing
d) Varies
Answer:b

2. What is the output of this C code?
#include
void main()
{
static int x = 3;
x++;
if (x <= 5) { printf(“hello”); main(); } } a) Run time error b) hello c) Infinite hello d) hello hello Answer:d 3. The value obtained in the function is given back to main by using ________ keyword? a) return b) static c) new d) volatile Answer:a 4. 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 Answer:d 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 6. What is the output of this code having void return-type function? #include
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

7. The output of the code below is
#include
void main()
{
int k = m();
printf(“%d”, k);
}
void m()
{
printf(“hello”);
}
a) hello 5
b) Error
c) Nothing
d) Garbage value
Answer:a

8. The output of the code below is
#include
int *m()
{
int *p = 5;
return p;
}
void main()
{
int *k = m();
printf(“%d”, k);
}
a) 5
b) Junk value
c) 0
d) Error
Answer:a

9. What will be the output of the program?
#include
int main()
{
int i=1;
if(!i)
printf(“SimpleWay2Code,”);
else
{
i=0;
printf(“C-Program”);
main();
}
return 0;
}
A. prints “SimpleWay2Code, C-Program” infinitely
B. prints “C-Program” infinetly
C. prints “C-Program, SimpleWay2Code” infinitely
D. Error: main() should not inside else statement
Answer:b

10. How many times the program will print “SimpleWay2Code” ?
#include
int main()
{
printf(“SimpleWay2Code”);
main();
return 0;
}
A. Infinite times
B. 32767 times
C. 65535 times
D. Till stack overflows
Answer:d