12

Misc

Question 1
In the C language (GATE CS 2002)
A
At most one activation record exists between the current activation record and the activation record for the main
B
The number of activation records between the current activation record and the activation record for the main depends on the actual function calling sequence.
C
The visibility of global variables depends on the actual function calling sequence.
D
Recursion requires the activation record for the recursive function to be saved on a different stack before the recursive function can be called.
Misc    
Discuss it


Question 1 Explanation: 
a) –> There is no such restriction in C language b) –> True c) –> False. In C, variables are statically scoped, not dynamically. c) –> False. The activation records are stored on the same stack.
Question 2
The C language is. (GATE CS 2002)
A
A context free language
B
A context sensitive language
C
A regular language
D
Parsable fully only by a Turing machine
Misc    
Discuss it


Question 2 Explanation: 
Most programming languages including C, C++, Java and Pascal can be approximated by context-free grammar and compilers for them have been developed based on properties of context-free languages.
Question 3
The number of tokens in the following C statement is (GATE 2000)
printf("i = %d, &i = %x", i, &i);
A
3
B
26
C
10
D
21
Misc    Lexical analysis    
Discuss it


Question 3 Explanation: 
In a C source program, the basic element recognized by the compiler is the “token.” A token is source-program text that the compiler does not break down into component elements. There are 6 types of C tokens : identifiers, keywords, constants, operators, string literals and other separators. There are total 10 tokens in the above printf statement. Below are tokens in above program.
printf
(
"i = %d, &i = %x"
, 
i
,
&
i
)
;
Question 4
Which of the following best describes C language
A
C is a low level language
B
C is a high level language with features that support low level programming
C
C is a high level language
D
C is a very high level language
Misc    
Discuss it


Question 5
Assume that the size of an integer is 4 bytes. Predict the output?
#include <stdio.h>
int fun()
{
    puts(" Hello ");
    return 10;
}

int main()
{
    printf("%d", sizeof(fun()));
    return 0;
}
A
4
B
Hello 4
C
4 Hello
D
Compiler Error
Misc    
Discuss it


Question 5 Explanation: 
sizeof() is an operator, not a function. It looks like a function though. The operands of operators need not to be evaluated. That is why fun() is not called.
Question 6
#include <stdio.h>
int main()
{
    int a[][3] = {1, 2, 3, 4, 5, 6};
    int (*ptr)[3] = a;
    printf("%d %d ", (*ptr)[1], (*ptr)[2]);
    ++ptr;
    printf("%d %d\n", (*ptr)[1], (*ptr)[2]);
    return 0;
}
A
2 3 5 6
B
2 3 4 5
C
4 5 0 0
D
none of the above
Misc    
Discuss it


Question 7
Consider line number 3 of the following C- program.
int main ( ) {                   /* Line 1 */
  int I, N;                      /* Line 2 */
  fro (I = 0, I < N, I++);       /* Line 3 */
}
Identify the compiler's response about this line while creating the object-module
A
No compilation error
B
Only a lexical error
C
Only syntactic errors
D
Both lexical and syntactic errors
Misc    GATE-CS-2005    
Discuss it


Question 7 Explanation: 
Note that there is 'fro' instead of 'for'. This is not a lexical error as lexical analysis typically involves Tokenization.
Question 8
Consider a program P that consists of two source modules M1 and M2 contained in two different files. If M1 contains a reference to a function defined in M2, the reference will be resolved at
A
Edit-time
B
Compile-time
C
Link-time
D
Load-time
Misc    GATE-CS-2004    
Discuss it


Question 8 Explanation: 
  Note: Static linking is done at link-time, dynamic linking or shared libraries are brought in only at runtime. (A) Edit-time : Function references can never be given/determined at edit-time or code-writing time. Function references are different from function names. Function names are used at edit-time and function references are determined at linker-time for static libraries or at runtime for dynamic libraries. (B) Compile-time : Compile time binding is done for functions present in the same file or module. (C) Link-time : Link time binding is done in the linker stage, where functions present in separate files or modules are referenced in the executable. (D) Load-time : Function referencing is not done at load-time. Hence, correct answer would be (C).   This solution is contributed by Vineet Purswani.
Question 9
Assume the following C variable declaration
int *A [10], B [10][10];
Of the following expressions
I.   A [2]
II.  A [2][3]
III. B [1]
IV.  B [2][3] 
which will not give compile-time errors if used as left hand sides of assignment statements in a C program ?
A
I, II and IV only
B
II, III and IV only
C
II and IV only
D
IV only
Misc    
Discuss it


Question 9 Explanation: 
Question 10
Consider the following C program:
# include <stdio.h>
int main( )
{
   int i, j, k = 0;
   j = 2 * 3 / 4 + 2.0 / 5 + 8 / 5;
   k  -= --j;
   for (i = 0; i < 5; i++)
   {
      switch(i + k)
      {
         case 1:
         case 2: printf("\n%d", i + k);
         case 3: printf("\n%d", i + k);
         default: printf("\n%d", i + k);
      }
   }
   return 0;
}
The number of times printf statement is executed is __________.
A
8
B
9
C
10
D
11
Misc    GATE-CS-2015 (Set 3)    
Discuss it


Question 10 Explanation: 
The following statement makes j = 2
 j = 2 * 3 / 4 + 2.0 / 5 + 8 / 5; 
The following statement makes k = -1.
  
 k  -= --j; 
There is one important thing to note in switch is, there is no break. Let count of printf statements be 'count'
For i = 0, the value of i+k becomes -1, default block 
           is executed, count = 1.
For i = 1, the value of i+k becomes 0, default block
           is executed, count = 2.
For i = 2, the value of i+k becomes 1, all blocks are 
           executed as there is no break, count = 5
For i = 3, the value of i+k becomes 2, three blocks 
           after case 1: are executed, count = 8
For i = 4, the value of i+k becomes 3, two blocks 
           are executed, count = 10 
There are 17 questions to complete.
12

Company Wise Coding Practice    Topic Wise Coding Practice