ExamVeda
Login
Home
31
What will happen after compiling and running following code?
main()
{ 
     printf("%p", main); 
}
Discuss
Answer & Solution
Answer: Option C
Solution:

Function names are just addresses (just like array names are addresses).
main() is also a function. So the address of function main will be printed. %p in printf specifies that the argument is an address. They will be printed as hexadecimal numbers.

32
Use of functions
Discuss
Answer & Solution
Answer: Option E
No explanation is given for this question. Let's Discuss on Board
33
Any C program
Discuss
Answer & Solution
Answer: Option A
Solution:
Option A: Must contain at least one function.

Explanation: In C programming, every valid program must contain at least one function, which is typically the main() function. This function serves as the starting point of execution for the program.

Option B: Need not contain any function.

Explanation: This option is incorrect because every C program requires at least one function, typically the main() function, to execute.

Option C: Needs input data.

Explanation: While many programs do require input data, this is not a requirement for the structure of a C program itself. Input data is dependent on the specific requirements of the program being developed.

Option D: None of the above.

Explanation: This option is incorrect because Option A is correct—every C program must contain at least one function.

Conclusion:
Option A: Must contain at least one function.
34
What is function?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
35
Determine output:
main()
{
      int i = abc(10);
      printf("%d", --i);
}

int abc(int i)
{
      return(i++);
}
Discuss
Answer & Solution
Answer: Option B
Solution:

return(i++) it will first return i and then increment. i.e. 10 will be returned.

36
The default parameter passing mechanism is
Discuss
Answer & Solution
Answer: Option A
Solution:
In C programming, the default parameter passing mechanism is call by value.

Call by value: In this mechanism, a copy of the actual parameter's value is passed to the function. The function operates on this copy, and changes made to the parameter within the function do not affect the original argument.

Call by reference: This is not the default mechanism in C. It involves passing the address of the actual parameter, allowing the function to modify the original value.

Call by value result: This mechanism is not used by default in C. It involves passing a copy of the actual parameter and then updating the original variable with the result after the function execution.

None of these: This option is incorrect because call by value is indeed the default parameter passing mechanism in C.

Thus, Option A: call by value is the correct answer.
37
What is the result of compiling and running this code?
main()
{
      char string[] = "Hello World";
      display(string);
}

void display(char *string)
{
      printf("%s", string);
}
Discuss
Answer & Solution
Answer: Option B
Solution:

Compiler Error : Type mismatch in redeclaration of function display
As the function display() is not defined before use, compiler will assume the return type of the function which is int(default return type). But when compiler will see the actual definition of display(), mismatch occurs since the function display() is declared as void. Hence the error.

38
Determine output:
main()
{
      int i = 5;
      printf("%d%d%d%d%d", i++, i--, ++i, --i, i);
}
Discuss
Answer & Solution
Answer: Option D
Solution:

The arguments in a function call are pushed into the stack from left to right. The evaluation is by popping out from the stack. and the evaluation is from right to left, hence the result. See the picture below
Function mcq solution image

39
Pick the correct statements.
I.   The body of a function should have only one return statement.
II.  The body of a function may have many return statements.
III. A function can return only one value to the calling environment.
IV. If return statement is omitted, then the function does its job but returns no value to the calling environment.
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
40
What will be the output of the following program code?
main()
{
      static int var = 5;
      printf("%d ", var--);
      if(var)
            main();
}
Discuss
Answer & Solution
Answer: Option B
Solution:

When static storage class is given, it is initialized once. The change in the value of a static variable is retained even between the function calls. Main is also treated like any other ordinary function, which can be called recursively.