Machine-translated by Google. Questions are authored in English.
Top

Functions Questions and Answers

Answer: D

Correct answer: Both (a) and (b)

An automatic variable is visible from its declaration to the end of the block that contains it, and that includes any blocks nested inside - unless one of them declares another variable of the same name, which shadows it.

Please log in or register to report this question.

12.

Functions can be called either by value or reference

Answer: A

Correct answer: True

C passes everything by value, but passing a pointer by value gives the function the caller’s address and so the effect of call by reference. Both styles are therefore available, which is why arrays - whose names decay to pointers - behave as though passed by reference.

Please log in or register to report this question.

13.

What is the output of the below code snippet?

#include <stdio.h>

main() 
{
   unsigned x = 5, y=&x, *p = y+0; 

   printf("%u",*p);
}

 

Answer: D

Correct answer: 5

y holds the address of x, and p is set to that same address, so *p is x itself - 5. (The code stores an address in an unsigned int, which is poor practice and provokes warnings; it happens to work only where a pointer and an unsigned int are the same width.)

Please log in or register to report this question.

14.

What is the output of this C code?
 

void m();
void n()
{
m();
}
void main()
{
void m()
{
printf("hi");
}
}

 

Answer: B

Correct answer: Compile time error

Two faults. Standard C does not allow a function to be defined inside another, and m is defined inside main here. And n, which calls m, is never called at all - so even if it compiled, nothing would be printed.

Please log in or register to report this question.

15.

Is an assignment statement that gives a value to a local static variable executed only once?

Answer: B

Correct answer: false

The initialisation of a static variable happens once, before the program starts. But an ordinary assignment to it inside the function is an executable statement like any other, and runs every time the function is called - which would defeat the whole point of making the variable static.

Please log in or register to report this question.

Answer: A

Correct answer: return-type function-name(argument type);

A declaration (prototype) states the return type, the name and the parameter types, and ends with a semicolon - no body. Adding a body makes it a definition, which is a different thing.

Please log in or register to report this question.

17.

What is the output of this C code?

void foo();
int main()
{
void foo();
foo();
return 0;
}
void foo()
{
printf("2 ");
}

 

Answer: B

Correct answer: 2

The function is declared at file scope and again inside main. Repeating a declaration is harmless as long as the two agree, which they do, so the program compiles and prints 2.

Please log in or register to report this question.

18.

Which of the following storage classes supports the char data type?

Answer: D

Correct answer: All of the mentioned

char works with every storage class: auto char, static char and register char are all valid. Storage class and type are independent choices - the first says where and how long the object lives, the second what it holds.

Please log in or register to report this question.

19.

What is the output of this C code?

int main()
{
void foo(), f();
f();
}
void foo()
{
printf("2 ");
}
void f()
{
printf("1 ");
foo();
}

 

Answer: B

Correct answer: 1 2

Declaring void foo(), f(); inside main is legal - it declares them, without defining them, and the declaration is simply local in scope. f() is then called; it prints 1 and calls foo, which prints 2. Output: 1 2.

Please log in or register to report this question.

20.

What is the format identifier for “static a = 20.5;”?

Answer: B

Correct answer: %d

With no type given, static a = 20.5; falls back on the old implicit int, so the value is truncated to 20 and the correct specifier is %d. The declaration is legal only under the pre-C99 rules; a modern compiler will warn or reject it.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Functions Questions and Answers || Functions MCQ Questions and Answers || Functions GK Questions and Answers || Functions GK MCQ Questions || Functions Multiple Choice Questions and Answers || Functions GK || GK on Functions || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming