Monday, 6 July 2015

Exercise - 1 (C Language Problems)  


Q.1. Consider the function
    find (int x, int y)
    { return ( ( x < y) ? 0 : ( x -y ) ) ; }
Let a , b be two non – negative integers. Which of the following calls finds the possible difference of a and b ?
a) find ( a , b) + find ( b , a )
b) find ( a , find ( a , b ) )
c) a + find ( a , b )
d) b + find ( a , b )

Q.2. The Statement
    if ( myPtr != NULL )
    *myPtr = NULL;
    else
   *myPtr = NULL;
has the same effect as the statement(s)
a) if ( myPtr ) *myPtr = NULL ;
else *myPtr = NULL;
b) *myPtr = NULL;
c) if ( !myPtr ) *myPtr = NULL ;
else *myPtr = NULL;
d) if ( myPtr == NULL ) *myPtr = NULL;
else *myPtr = NULL;

Q.3. The following program fragment
    if ( a= 7)
    printf( “ a is seven ” );
    else
    printf( “ a is not seven ” );
results in the printing of
a) a is seven
b) a is not seven
c) nothing
d) garbage value

Q.4. The following loop
     for ( for i = 1, j = 10 ; i < 6 ; ++ i, --j)
     printf(“%d %d”, i, j);
prints
a) 1 10 2 9 3 8 4 7 5 6
b) 1 2 3 4 5 10 9 8 7 6
c) 1 1 1 1 1 9 9 9 9 9
d) none of the above

Q.5. The following Program
main()
{
    int i=5;
    if (i==5) return;
    else printf(“i is not five ” ) ;
    printf(“over”);
}
results in
a) a syntax error
b) an execution error
c) printing of over
d) execution termination, without printing anything

Q.6. Consider the following program fragment
    if ( a > b )
    printf( “ a > b” );
    else
    printf(“else part”);
    printf(“ a < = b”);
a <= b will be printed if
a) a > b
b) a < b
c) a == b
d) None of the above 

Q.7. Consider the following program 
void main()
{
     int counter = 40;
     for(;counter;)
     printf("Sample");
     printf("%d",counter);
}
What will be the output?
a) 40
b) -40
c) 0
d) None of these

Q.8. What will be the output of following program?
void main()
{
     static char a[ ] = "JAIPUR";
     char * b = "JAIPUR";
     printf("\n %d %d", size of (a), size of (b));
}
a) a = 7, b = 7
b) a = 7, b = 2
c) a = 2, b = 7
d) a = 7, b = 0

Q.9. printf("%d",printf("Hello"));
a) results in a syntax error
b) outputs Hello5
c) outputs garbage
d) prints Hello and terminates abruptly 

Q.10. If n has the value 3 then the output of the statement 
     printf("%d %d", n++ , ++n ); is
a) 3   5
b) 4   5
c) 4   4
d) is implementation dependent

Q.11. printf("%c", 100);
a) prints 100
b) prints the ASCII equivalent of 100
c) prints garbage
d) none of the above

Q.12. printf("%f", 9/5);   prints
a) 1.8
b) 1.0
c) 2.0
d) none of the above

Q.13. The following program fragment
     for( i = 3; i < 15; i += 3 );
     printf("%d", i );
results in 
a) a syntax error
b) an execution error
c) printing of 12
d) printing of 15

Q.14. The following program fragment
    for ( i =1; i <5; ++i )
    if ( i == 3) continue;
    else printf("%d", i );
results in the printing of
a) 1  2  4  5
b) 1  2  4
c) 2  4  5
d) None of these

Q.15. The statement 
     printf("%f", (float) 9/5);
prints
a) 1.8
b) 1.0
c) 2.0
d) none of the above

Q.16. The following program fragment
     if(a = 0)
     printf("a is zero");
     else
     printf("a is not zero");
results in the print of 
a) a is zero
b) a is not zero
c) nothing
d) garbage

Q.17. The following program fragment
     int k = -7
     printf("%d", 0 < !k);
a) prints 0
b) prints a non-zero value
c) is illegal
d) prints an unpredictable value

Q.18. The following program fragment 
     int i  = 107, x = 5;
     printf( (x > 7) ? "%d" : "%c",  i );
results in 
a) an execution error
b) a syntax error
c) printing of k
d) none of the above

Q.19. The following statements
     for( i = 3; i < 15 ;  i += 3)
     {
        printf("%d", i);
        ++i;
      }
will result in the print of 
a) 3  6  9  12
b) 3  6  9  12  15
c) 3  7  11
d) 3  7  11  15

Q.20. The following program fragment
    void main()
    {
      int x = 0;
      while(x <= 10)
      for(;;)
      if(++x%10 == 0)
      break;
      printf("%d", x);
     }
results in
a) printing of 10
b) printing of 20
c) infinite loop
d) none of the above

No comments:

Post a Comment