• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C Variable Declaration and Scope

Question 11

What will be the output of the following C code? C
#include <stdio.h>
int main()
{
int i;
for ( i=0; i<5; i++ )
{
   int i = 10;
   printf ( \"%d \", i );
   i++;
}
return 0;
}
  • 10 11 12 13 14
  • 10 10 10 10 10
  • 0 1 2 3 4
  • Compilation error

Question 12

Given i= 0, j = 1, k = – 1 x = 0.5, y = 0.0 What is the output of given ‘C’ expression ? x * 3 & & 3 || j | k
  • -1
  • 0
  • 1
  • 2

Question 13

Assume that the program ‘P’ is implementing parameter passing with ‘call by reference’. What will be printed by following print statements in P? Program P( ) { x = 10; y = 3; funb (y, x, x) print x; print y; } funb (x, y, z) { y = y + 4; z = x + y + z; }
  • 10, 7
  • 31, 3
  • 10, 3
  • 31, 7

Question 14

When an array is passed as parameter to a function, which of the following statements is correct?
  • The function can change values in the original array.
  • In C, parameters are passed by value, the function cannot change the original value in the array.
  • It results in compilation error when the function tries to access the elements in the array.
  • Results in a run time error when the function tries to access the elements in the array.

Question 15

Consider the following statements S1, S2 and S3 : S1 : In call-by-value, anything that is passed into a function call is unchanged in the caller’s scope when the function returns. S2 : In call-by-reference, a function receives implicit reference to a variable used as argument. S3 : In call-by-reference, caller is unable to see the modified variable used as argument.
  • S3 and S2 are true.
  • S3 and S1 are true.
  • S2 and S1 are true.
  • S1, S2, S3 are true.

Question 16

Consider the program below in a hypothetical language which allows global variable and a choice of call by reference or call by value methods of parameter passing. C
 int i ;
program main ()
{
    int j = 60;
    i = 50;
    call f (i, j);
    print i, j;
}
procedure f (x, y)
{           
    i = 100;
    x = 10;
    y = y + i ;
}
Which one of the following options represents the correct output of the program for the two parameter passing mechanisms?
  • Call by value : i = 70, j = 10; Call by reference : i = 60, j = 70
  • Call by value : i = 50, j = 60; Call by reference : i = 50, j = 70
  • Call by value : i = 10, j = 70; Call by reference : i = 100, j = 60
  • Call by value : i = 100, j = 60; Call by reference : i = 10, j = 70

Question 17

What is the output of the following program? 
 

#include 
int tmp=20;
main( )
{
printf("%d ",tmp);
func( );
printf("%d ",tmp);
}
func( )
{
static int tmp=10;
printf("%d ",tmp);
}


 

  • 20 10 10
     

  • 20 10 20
     

  • 20 20 20
     

  • 10 10 10
     

There are 17 questions to complete.

Last Updated :
Take a part in the ongoing discussion