C Misc

  • Last Updated : 01 Sep, 2021

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


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)
Cross
A context free language
Tick
A context sensitive language
Cross
A regular language
Cross
Parsable fully only by a Turing machine


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

printf("HELLO WORLD");
Cross

3

Tick

5

Cross

9

Cross

8



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 5 tokens in the above printf statement. Below are tokens in above program.

printf
(
"HELLO WORLD"
)
;
Question 4
Which of the following best describes C language
Cross
C is a low level language
Tick
C is a high level language with features that support low level programming
Cross
C is a high level language
Cross
C is a very high level language


Question 5

Assume that the size of an integer is 4 bytes. Predict the output? 

C

#include <stdio.h>
int fun()
{
    puts(" Hello ");
    return 10;
}

int main()
{
    printf("%d", sizeof(fun()));
    return 0;
}
Tick

4

Cross

Hello 4

Cross

4 Hello

Cross

Compiler Error



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;
}
Tick
2 3 5 6
Cross
2 3 4 5
Cross
4 5 0 0
Cross
none of the above


Question 7

Consider line number 3 of the following C- program. 

C

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

Cross

No compilation error

Cross

Only a lexical error

Cross

Only syntactic errors

Tick

Both lexical and syntactic errors



Question 7-Explanation: 

Lexical errors refer to errors related to the lexemes or tokens in the program, such as misspelled keywords or identifiers that are not recognized by the language. Here, "fro" instead of "for".
Syntactic errors occur when the code violates the grammar or syntax rules of the programming language. Here, inside  for loop there is coma instead of semicolomn

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
Cross
Edit-time
Cross
Compile-time
Tick
Link-time
Cross
Load-time


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 

C

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 ?

Tick

I, II and IV only

Cross

II, III and IV only

Cross

II and IV only

Cross

IV only



Question 9-Explanation: 

A is an array of pointers to int, and B is a 2-D array.

  • A[2]= can take a pointer
  • A[2][3]= can take an int
  • B[1]=B[1] is the base address of the array and it cannot be changed as array in C is a constant pointer.
  • B[2][3]= can take an integer

So, option (A) is the answer.

Question 10

The C language is:

Cross

A context free language

Tick

A context sensitive language

Cross

A regular language

Cross

Parsable fully only by a Turing machine



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;
  1. 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

123
There are 25 questions to complete.