C Misc

123
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.
C 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
C Misc    
Discuss it


Question 2 Explanation: 
C and C++ are context-sensitive languages. There are several reasons:
  1. To parse C and C++, you start by using a very powerful preprocessor. These preprocessors are inevitably written by hand (they are not based on a theoretic foundation like regular expressions or context-free grammars).
  2. The grammar is ambiguous: it has LR conflicts, such as the if-then-else conflict. Parsers typically resolve this using context (an “else” matches the closest “if”).
  3. C and C++ lexers require lexical feedback to differentiate between typedef names and identifiers. That is, the context-sensitive lexer needs help from the “context-free” parser to distinguish between an identifier “foo” and a typedef name “foo”. In this snippet,
    int foo;
    typedef int foo;
    foo x;
    the first “foo” is an identifier while the second and third are typedef names. You need to parse typedef declarations to figure this out (and since types have nested parentheses, this is definitely at least as hard as parsing a context-free language). This means that the parser and lexer are mutually recursive, so it doesn’t make sense to say that the parser is context free while the lexer is context sensitive.
Ref: C and C++ are not context free
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
C 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
C 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
C 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 %dn", (*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
C 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
C 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
C 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
C Misc    
Discuss it


Question 9 Explanation: 
Question 10
The C language is:
A
A context free language
B
A context sensitive language
C
A regular language
D
Parasble fully only by a Turing machine
C Misc    GATE-CS-2002    
Discuss it


Question 10 Explanation: 
C and C++ are context-sensitive languages. There are several reasons:
  1. To parse C and C++, you start by using a very powerful preprocessor. These preprocessors are inevitably written by hand (they are not based on a theoretic foundation like regular expressions or context-free grammars).
  2. The grammar is ambiguous: it has LR conflicts, such as the if-then-else conflict. Parsers typically resolve this using context (an “else” matches the closest “if”).
  3. C and C++ lexers require lexical feedback to differentiate between typedef names and identifiers. That is, the context-sensitive lexer needs help from the “context-free” parser to distinguish between an identifier “foo” and a typedef name “foo”. In this snippet,
    int foo;
    typedef int foo;
    foo x;
    the first “foo” is an identifier while the second and third are typedef names. You need to parse typedef declarations to figure this out (and since types have nested parentheses, this is definitely at least as hard as parsing a context-free language). This means that the parser and lexer are mutually recursive, so it doesn’t make sense to say that the parser is context free while the lexer is context sensitive.
Ref: C and C++ are not context free
There are 25 questions to complete.
123


My Personal Notes arrow_drop_up