0% found this document useful (0 votes)
914 views32 pages

C

The document contains 10 multiple choice questions about C language concepts. The questions cover topics like variable declaration, data types, operators, functions, structures, pointers, macros and more. Each question includes 4 possible answers and an explanation of the correct answer. This technical quiz tests knowledge of basic as well as some advanced C programming concepts.

Uploaded by

Aniket Shirke
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
914 views32 pages

C

The document contains 10 multiple choice questions about C language concepts. The questions cover topics like variable declaration, data types, operators, functions, structures, pointers, macros and more. Each question includes 4 possible answers and an explanation of the correct answer. This technical quiz tests knowledge of basic as well as some advanced C programming concepts.

Uploaded by

Aniket Shirke
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

C Language Questions for technical quiz

#1: Which is valid C expression?


a) int my_num = 100,000;
b) int my_num = 100000;
c) int my num = 1000;
d) int $my_num = 10000;
Show Answer
Answer: b
Explanation: space, comma and $ cannot be used in a variable name.
#2: What is the output of this C code?
#include <stdio.h>
int main()
{
    printf("Hello World! %d \n", x);
    return 0;
}

a) Hello World! x;
b) Hello World! followed by a junk value
c) Compile time error
d) Hello World!
Show Answer
Answer: c
Explanation: It results in an error since x is used without declaring the variable x.
#3: What will happen if the below program is executed?
#include <stdio.h>
int main()
{
    int main = 3;
    printf("%d", main);
    return 0;
}

a) It will cause a compile-time error


b) It will cause a run-time error
c) It will run without any error and prints 3
d) It will experience infinite looping
Show Answer
Answer: c
Explanation: A C program can have same function name and same variable name.
#4: What is the output of this C code?
#include  <stdio.h>
int main()
{
   char chr;
   chr = 128;
   printf("%d\n", chr);
   return 0;
}

a) 128
b) -128
c) Depends on the compiler
d) None of the mentioned
Show Answer
Answer: b
Explanation: signed char will be a negative number.
#5: What is the output of this C code?
#include <stdio.h>
int main()
{
    char *p[1] = {"hello"};
    printf("%s", (p)[0]);
    return 0;
}

a) Compile time error


b) Undefined behaviour
c) hello
d) None of the mentioned
Show Answer
Answer: c
Explanation: None
#6: What is the output of this C code?
#include <stdio.h>
int main()
{
    printf("crazyfor\code\n");
    return 0;
}

a) crazyforcode
b) crazyfor
code
c) codeyfor
d) crazyfor
Show Answer
Answer: c
Explanation: r is carriage return and moves the cursor back. sanfo is replaced by class
#7: Which among the following is NOT a logical or relational operator?
a) !=
b) ==
c) ||
d) =
Show Answer
Answer: d
Explanation: None
#8: What is the output of this C code?
#include <stdio.h>
int main()
{
    int a = 10;
    if (a == a--)
        printf("TRUE 1\t");
    a = 10;
    if (a == --a)
        printf("TRUE 2\t");
}
a) TRUE 1
b) TRUE 2
c) TRUE 1 TRUE 2
d) No output
Show Answer
Answer: c
Explanation: None
#9: The scope of an automatic variable is:
a) Within the block it appears
b) Within the blocks of the block it appears
c) Until the end of program
d) Both (a) and (b)
Show Answer
Answer: d
Explanation: None
#10: Default storage class if not any is specified for a local variable, is auto
a) true
b) false
c) Depends on the standard
d) None of the mentioned
Show Answer
Answer: a
Explanation: None
#1: What is the scope of an external variable?
a) Whole source file in which it is defined
b) From the point of declaration to the end of the file in which it is defined
c) Any source file in a program
d) From the point of declaration to the end of the file being compiled
Show Answer
Answer: d
Explanation: none.
#2: What is the output of this C code?
#include <stdio.h>
void main()
{
    int x = 97;
    int y = sizeof(x++);
    printf("x is %d", x);
}

a) x is 97
b) x is 98
c) x is 99
d) Run time error
Show Answer
Answer: a
Explanation: none.
#3: What is the output of the below c code?
#include <stdio.h>
void main()
{
    char *s = "hello";
    char *p = s;
    printf("%p\t%p", p, s);
}

a) Different address is printed


b) Same address is printed
c) Run time error
d) Nothing
Show Answer
Answer: b
Explanation: none.
#4: What is the output of this C code?
#include <stdio.h>
struct student
{
    char a[5];
};
void main()
{
    struct student s[] = {"hi", "hey"};
    printf("%c", s[0].a[1]);
}

a) h
b) i
c) e
d) y
Show Answer
Answer: b
Explanation: none.
#5: What is the output of this C code?
#include <stdio.h>
void main()
{
    static int x;
    if (x++ < 2)
    main();
}

a) Infinite calls to main


b) Run time error
c) Varies
d) main is called twice
Show Answer
Answer: d
Explanation: none.
#6: What is the output of this C code?
#include <stdio.h>
int main()
{
    char *str = "hello, world";
    char *str1 = "hello, world";
    if (strcmp(str, str1))
        printf("equal");
    else
        printf("unequal");
}
a) equal
b) unequal
c) Compilation error
d) Depends on the compiler
Show Answer
Answer: cb
Explanation: none.
#7: Which of the following cannot be static in C?
a) Variables
b) Functions
c) Structures
d) None of the mentioned
Show Answer
Answer: d
Explanation: none.
#8: What is the output of this C code?
#include <stdio.h>
#define foo(m, n) m * n = 10
int main()
{
    printf("in main\n");
}

a) In main
b) Compilation error as lvalue is required for the expression m*n=10
c) Preprocessor error as lvalue is required for the expression m*n=10
d) None of the mentioned
Show Answer
Answer: a
Explanation: Preprocessor just replaces whatever is given compiler then checks for error at the replaced
part of the code. Here it is not replaced anywhere.
Output:
$ cc pgm1.c
$ a.out
in main
#9: Which of the following is not possible?
a) A structure variable pointing to itself
b) A structure variable pointing to another structure variable of same type
c) 2 different type of structure variable pointing at each other.
d) None of these
Show Answer
Answer: d
Explanation: none.
#10: Property of external variable to be accessed by any source file is called by C90 standard as
a) external linkage
b) external scope
c) global scope
d) global linkage
Show Answer
Answer: a
Explanation: None
#1: Predict the output of the following C snippets?
int main()
{
    char *g = NULL;
    char *h = 0;
    if (g)
        printf(" g ");
    else
    printf("nullg");
    if (h)
        printf("h\n");
    else
        printf(" nullh\n");
}

a) nullg nullh
b) Depends on the compiler
c) g nullh
d) g h
Show Answer
Answer: a
Explanation: none.
#2: What is the output of this C code?
void main ()
{
    int a=2;
    if(a==2)
    {
        a=~a+2<<1;
        printf("%d",a);
    }
    else
    {
        a=~a;
    }
}

a) 6
b) -2
c) 0
d) None of above
Show Answer
Answer: b
Explanation: none.
#3: What is the output of the below c code?

int main()
{
     static int i;
     int j;
     for(j=0;j<=5;j+=2)
     switch(j)
     {
        case 1: i++;break;
        case 2: i+=2;
        case 4: i%=2;j=-1;continue;
        default: --i; continue;
     }
     printf ("%d", i);
     return 0;
}
a) Different address is printed
b) Same address is printed
c) Run time error
d) Nothing
Show Answer
Answer: c
Explanation: Explanation:
JI
00
2 -1
-1 -1
12
31
50
Difference between continue and break:
Let’s take an example:
int n;
for(n = 0; n < 27; ++n)
{
break;
}
printf ("%d", n);
In case of break, the loop terminates and the value of n is 0.
int n;
for(n = 0; n < 27; ++n)
{
continue;
}
printf ("%d", n);
In case of break, the program counter to return to the first line of the loop the final value of n is 27.
In case of break the conditions are checked and the value of n is incremented till the end.
#4: What is the output of this C code?

int main()
{
    int a=8,b=2,c;
    c=a<<b;
    printf("%d",c);
    return 0;
}
a) 32
b) 16
c) 8
d) 4
Show Answer
Answer: a
Explanation: Write 8 in binary system(1000) and shift it towards left by 2 i.e. 100000 which is 32 in
decimal system.
#5: What is the output of this C code?

int main()
{
    char c='8';
    printf("%d",c);
    return 0;
}

a) 56
b) 16
c) 8
d) 4
Show Answer
Answer: a
Explanation: 64-8
#6: What is the output of this C code?

int main()
{
    int x = 100;
    printf("decimal = %d; octal = %o; hex = %x\n", x, x, x);
    printf("decimal = %d; octal = %#o; hex = %#x\n", x, x, x);
    return 0;
}

a) decimal = 100; octal = 414; hex = 46


b) decimal = 100; octal = 414; hex = 64
c) decimal = 100; octal = 144; hex = 64
d) decimal = 100; octal = 144; hex = 46
Show Answer
Answer: c
Explanation: Decimal to Hexa conversion:
100/16 Quotient 6; Remainder 4
6/16 Quotient 0; Remainder 6
Writing the remainders in down to upward direction we get 64
Decimal to Octal conversion:
100/8 Quotient 12; Remainder 4
12/8 Quotient 1; Remainder 4
1/8 Quotient 0; Remainder 1
Writing the remainders in down to upward direction we get 144
#7: What is the output of this C code?

struct student
{  };
int main()
{
    struct student s;
    printf("%d", sizeof(s));
}

a) 1
b) 0
c) Compilation Error
d) Runtime Error
Show Answer
Answer: b
Explanation: none.
#8: What is the output of this C code?

    int main(){
    int a=10;
    switch(0)
    printf("%d",a);
    switch(1)
    printf("%d",a);
    return 0;
}
a) 10 10
b) 10
c) Compilation Error
d) No output
Show Answer
Answer: d
Explanation: None
#9: Output?

int main()
{
    printf("%d", max);
}
#define max 23

a) 23
b) 0
c) Compilation Error
d) Runtime Error
Show Answer
Answer: d
Explanation: #define has to be defined prior to the use of the macro.
#10: Output?

int main()
{
    int arri[] = {1, 2 ,3};
    int *ptri = arri;
    char arrc[] = {1, 2 ,3};
    char *ptrc = arrc;
    printf("sizeof arri[] = %d ", sizeof(arri));
    printf("sizeof ptri = %d ", sizeof(ptri));
    printf("sizeof arrc[] = %d ", sizeof(arrc));
    printf("sizeof ptrc = %d ", sizeof(ptrc));
    return 0;
}
a) sizeof arri[] = 12 sizeof ptri = 8 sizeof arrc[] = 12 sizeof ptrc = 8
b) sizeof arri[] = 12 sizeof ptri = 8 sizeof arrc[] = 3 sizeof ptrc = 8 ANS
#1: Predict the output of the following C snippets?

int main()
{
    char *g = NULL;
    char *h = 0;
    if (g)
        printf(" g ");
    else
    printf("nullg");
    if (h)
        printf("h\n");
    else
        printf(" nullh\n");
}

a) nullg nullh
b) Depends on the compiler
c) g nullh
d) g h
Show Answer
Answer: a
Explanation: none.
#2: What is the output of this C code?

void main ()
{
    int a=2;
    if(a==2)
    {
        a=~a+2<<1;
        printf("%d",a);
    }
    else
    {
        a=~a;
    }
}
a) 6
b) -2
c) 0
d) None of above
Show Answer
Answer: b
Explanation: none.
#3: What is the output of the below c code?

int main()
{
     static int i;
     int j;
     for(j=0;j<=5;j+=2)
     switch(j)
     {
        case 1: i++;break;
        case 2: i+=2;
        case 4: i%=2;j=-1;continue;
        default: --i; continue;
     }
     printf ("%d", i);
     return 0;
}

a) Different address is printed


b) Same address is printed
c) Run time error
d) Nothing
Show Answer
Answer: c
Explanation: Explanation:
JI
00
2 -1
-1 -1
12
31
50
Difference between continue and break:
Let’s take an example:
int n;
for(n = 0; n < 27; ++n)
{
break;
}
printf ("%d", n);
In case of break, the loop terminates and the value of n is 0.
int n;
for(n = 0; n < 27; ++n)
{
continue;
}
printf ("%d", n);
In case of break, the program counter to return to the first line of the loop the final value of n is 27.
In case of break the conditions are checked and the value of n is incremented till the end.
#4: What is the output of this C code?

int main()
{
    int a=8,b=2,c;
    c=a<<b;
    printf("%d",c);
    return 0;
}

a) 32
b) 16
c) 8
d) 4
Show Answer
Answer: a
Explanation: Write 8 in binary system(1000) and shift it towards left by 2 i.e. 100000 which is 32 in
decimal system.
#5: What is the output of this C code?

int main()
{
    char c='8';
    printf("%d",c);
    return 0;
}

a) 56
b) 16
c) 8
d) 4
Show Answer
Answer: a
Explanation: 64-8
#6: What is the output of this C code?

int main()
{
    int x = 100;
    printf("decimal = %d; octal = %o; hex = %x\n", x, x, x);
    printf("decimal = %d; octal = %#o; hex = %#x\n", x, x, x);
    return 0;
}

a) decimal = 100; octal = 414; hex = 46


b) decimal = 100; octal = 414; hex = 64
c) decimal = 100; octal = 144; hex = 64
d) decimal = 100; octal = 144; hex = 46
Show Answer
Answer: c
Explanation: Decimal to Hexa conversion:
100/16 Quotient 6; Remainder 4
6/16 Quotient 0; Remainder 6
Writing the remainders in down to upward direction we get 64
Decimal to Octal conversion:
100/8 Quotient 12; Remainder 4
12/8 Quotient 1; Remainder 4
1/8 Quotient 0; Remainder 1
Writing the remainders in down to upward direction we get 144
#7: What is the output of this C code?

struct student
{  };
int main()
{
    struct student s;
    printf("%d", sizeof(s));
}

a) 1
b) 0
c) Compilation Error
d) Runtime Error
Show Answer
Answer: b
Explanation: none.
#8: What is the output of this C code?

    int main(){
    int a=10;
    switch(0)
    printf("%d",a);
    switch(1)
    printf("%d",a);
    return 0;
}

a) 10 10
b) 10
c) Compilation Error
d) No output
Show Answer
Answer: d
Explanation: None
#9: Output?

int main()
{
    printf("%d", max);
}
#define max 23

a) 23
b) 0
c) Compilation Error
d) Runtime Error
Show Answer
Answer: d
Explanation: #define has to be defined prior to the use of the macro.
#10: Output?

int main()
{
    int arri[] = {1, 2 ,3};
    int *ptri = arri;
    char arrc[] = {1, 2 ,3};
    char *ptrc = arrc;
    printf("sizeof arri[] = %d ", sizeof(arri));
    printf("sizeof ptri = %d ", sizeof(ptri));
    printf("sizeof arrc[] = %d ", sizeof(arrc));
    printf("sizeof ptrc = %d ", sizeof(ptrc));
    return 0;
}

a) sizeof arri[] = 12 sizeof ptri = 8 sizeof arrc[] = 12 sizeof ptrc = 8


b) sizeof arri[] = 12 sizeof ptri = 8 sizeof arrc[] = 3 sizeof ptrc = 8 ANS
c) sizeof arri[] = 12 sizeof ptri = 4 sizeof arrc[] = 3 sizeof ptrc = 8
d) sizeof arri[] = 12 sizeof ptri = 4 sizeof arrc[] = 3 sizeof ptrc = 8
Show Answer
Answer: b
Explanation: Size of pointer is independent of data type.
c) sizeof arri[] = 12 sizeof ptri = 4 sizeof arrc[] = 3 sizeof ptrc = 8
d) sizeof arri[] = 12 sizeof ptri = 4 sizeof arrc[] = 3 sizeof ptrc = 8
Show Answer
Answer: b
Explanation: Size of pointer is independent of data type.
#1: Predict the output of the following C snippets
int main()
{
    int main = 56;
    printf("%d", main);
    return 0;
}

a) Compiler Error
b) Depends on the compiler
c) 56
d) none of above
Show Answer
Answer: c
Explanation: main is not a keyword in C.
#2: What is the output of this C code?
#include<stdio.h>
int main()
{
   float a = 3.14, *fptr;
   fptr = &a;
 
   printf("Size of Float Pointer : %d", sizeof(fptr));
   return (0);
}

a) Size of Float Pointer : 2


b) Size of Float Pointer : 4
c) Size of Float Pointer : 6
d) Size of Float Pointer : 8
Show Answer
Answer: d
Explanation: none.
#3: What is the output of the below c code?
#include<stdio.h>
int main()
{
    char ch;
    if(ch = printf(""))
        printf("It matters\n");
    else
        printf("It doesn't matters\n");
    return 0;
}

a) It matters
b) It doesn’t matters
c) Run time error
d) Nothing
Show Answer
Answer: b
Explanation: printf returns the number of characters successfully written on output.Hence ch=0 and
else statement executes.
#4: How many times is Hello world printed ?

int main()
{
    fork();
    fork();
    printf("Hello world\n");
}

a) 1
b) 2
c) 4
d) 8
Show Answer
Answer: c
Explanation: fork is an operation wherein the process makes another copy of itself.
#5: What is the output of this C code?

void main()
{
    int i, j;
    for(i=0,j=0;i<10,j<20;i++,j++){
        printf("i=%d \t j=%d\n", i, j);
    }
}

a) print i and j till 19


b) print i till 9 and j till 19
c) print i and j till 9
d) Runtime error
Show Answer
Answer: a
Explanation: none.
#6: What is the output of this C code?
#include<stdio.h>
int main()
{
    int x=1, y=0,z=5;
    int a=x&&y||++z;
    printf("%d",z++);
}

a) 1
b) 5
c) 6
d) 7
Show Answer
Answer: c
Explanation: and operator doesnt operate if second argument is zero. & operator has more precedence
than ||
#7: What is the output of this C code?
#include<stdio.h>
int main()
{
    int y = 2;
    int z = y +(y = 10);
    printf("%d\n", z);
}
a) 2
b) 4
c) 20
d) Compile time error
Show Answer
Answer: c
Explanation: none.
#8: What is the output of this C code?
#define max(a) a
int main()
{
    int x = 1;
    switch (x)
    {
        case max(2):
            printf("yes\n");
        case max(1):
            printf("no\n");
        break;
    }
}

a) yes
b) no
c) Runtime error
d) Compile time error
Show Answer
Answer: b
Explanation: Preprocessor just replaces whatever is given such that max(1) is replaced by 1 and switch
case 1 is executed.
#9: Which of the following is not a standard C Library?
a) errno.h
b) setjmp.h
c) signal.h
d) retarg.h
Show Answer
Answer: d
Explanation: none.
#10: What is the output of this C code?
#include<stdio.h>
int main()
{
        int x=35;
        printf("%d %d %d",x==35,x=50,x>40);
        return 0;
}

a) 1 50 1
b) 0 50 0
c) Runtime error
d) Compile time error
Show Answer
Answer: b
Explanation: Compiler executes right to left.

Q 1 - What is the output of the below code snippet?


#include<stdio.h>

main()
{
char s[]="hello", t[]="hello";

if(s==t){
printf("eqaul strings");
}
}

A - Equal strings
B - Unequal strings
C - No output
D - Compilation error
Answer : C

Explanation
No output, as we are comparing both base addresses and they are not same.
Q 2 - Which operator is used to continue the definition of macro in the next line?
A-#
B - ##
C-$
D-\

Answer : D

Explanation
\, the first two are stringize and token pasting operators respectively. There is no such operator called $.
Q 3 - Choose the invalid identifier from the below
A - Int
B - volatile
C - DOUBLE
D - __0__

Answer : B

Explanation
volatile is the reserved keyword and cannot be used an identifier name.
Q 4 - For the below definition what is the data type of ‘PI’
#define PI 3.141

A - Its float
B - Its double
C - There is no type associated with PI, as it’s just a text substitution
D - Syntax error, semi colon is missing with the definition of PI
Answer : C

Explanation
The text associated with the macro name gets expanded at the line of call. The expanded text is by
default a double constant whereas no type is associated with PI.
Q 5 - What is the output of the following program?
#include<stdio.h>

main()
{
int x = 3;

x += 2;
x =+ 2;
printf("%d", x);
}

A-2
B-5
C-7
D - Compile error

Answer : A

Explanation
+ in unary form is dummy operator, therefore ‘x’ is overwritten with the value +2 finally.
Q 6 - Choose the correct program that round off x value (a float value) to an int value to return the
output value 4,
A - float x = 3.6;
     int y = (int)(x + 0.5);
     printf ("Result = %d\n", y );
B - float x = 3.6;
     int y = int(x + 0.5);
     printf ("Result = %d\n", y );
C - float x = 3.6;
     int y = (int)x + 0.5
     printf ("Result = %d\n", y );
D - float x = 3.6;
     int y = (int)((int)x + 0.5)
     printf ("Result = %d\n", y );

Answer : A

Explanation
#include <math.h>
#include <stdio.h>

int main()
{
float x = 3.6;

int y = (int)(x + 0.5);

printf ("Result = %d\n", y );


return 0;

Q 7 - The correct order of mathematical operators in mathematics and computer programming,


A - Addition, Subtraction, Multiplication, Division
B - Division, Multiplication, Addition, Subtraction
C - Multiplication, Addition, Division, Subtraction
D - Mathematical operators can be done in any order

Answer : B

Explanation
It is BODMAS.
Q 8 - How many times the given below program will print "India"?
#include<stdio.h>

int main ()
{
int x;

for(x=-1; x<=20; x++)int i;


{
if(x < 10)
continue;
else
break;
printf("India");
}

A - Unlimited times
B - 21 times
C - 0 times
D - 20 times

Answer : C

Explanation
Following for loop there is only one statement, that is int i; break & continue are appearing out side for
block which is compile error
#include<stdio.h>

int main ()
{
int x;

for(x=-1; x<=20; x++)int i;


{
if(x < 10)
continue;
else
break;
printf("India");
}

Q 9 - Choose the correct order from given below options for the calling function of the code “a = f1(23,
14) * f2(12/4) + f3();”?
A - f1, f2, f3
B - f3, f2, f1
C - f2, f1, f3
D - Order may vary from one compiler to another

Answer : D

Explanation
Evaluation order is implementation dependent.
Q 10 - Which statement can print \n on the screen?
A - printf("\\n");
B - printf("n\");
C - printf("n");
D - printf('\n');
Answer : A

Explanation
Option A is the correct answer. In C programming language, "\n" is the escape sequence for printing a
new line character. In printf("\\n"); statement, "\\" symbol will be printed as "\" and “n” will be known
as a common symbol.

1. Consider the following three C functions :


filter_none
edit
play_arrow
brightness_4
[PI] int * g (void) 

  int x = 10; 
  return (&x); 

  
[P2] int * g (void) 

  int * px; 
  *px = 10; 
  return px; 
}
   
[P3] int *g (void) 

  int *px; 
  px = (int *) malloc (sizeof(int)); 
  *px = 10;
  return px; 

Which of the above three functions are likely to cause problems with pointers? (GATE 2001)
(a) Only P3
(b) Only P1 and P3
(c) Only P1 and P2
(d) P1, P2 and P3
Answer: (c)
Eplaination: In P1, pointer variable x is a local variable to g(), and g() returns pointer to this variable.
x may vanish after g() has returned as x exists on stack. So, &x may become invalid.
In P2, pointer variable px is being assigned a value without allocating memory to it.
P3 works perfectly fine. Memory is allocated to pointer variable px using malloc(). So, px exists on
heap, it’s existence will remain in memory even after return of g() as it is on heap.

2. The value of j at the end of the execution of the following C program. (GATE CS 2000)
filter_none
edit
play_arrow
brightness_4
int incr (int i)
{
   static int count = 0;
   count = count + i;
   return (count);
}
main ()
{
   int i,j;
   for (i = 0; i <=4; i++)
      j = incr(i);
}

(a) 10
(b) 4
(c) 6
(d) 7
Answer (a)
Eplaination: count is static variable in incr(). Statement static int count = 0 will assign count to 0 only
in first call. Other calls to this function will take the old values of count.
Count will become 0 after the call incr(0)
Count will become 1 after the call incr(1)
Count will become 3 after the call incr(2)
Count will become 6 after the call incr(3)
Count will become 10 after the call incr(4)

3. Consider the following C declaration


filter_none
edit
play_arrow
brightness_4
struct { 
    short s [5] 
    union { 
         float y; 
         long z; 
    }u; 
} t; 

Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes,
respectively. The memory requirement for variable t, ignoring alignment
considerations, is (GATE CS 2000)
(a) 22 bytes
(b) 14 bytes
(c) 18 bytes
(d) 10 bytes
Answer: (c)
Explanation: Short array s[5] will take 10 bytes as size of short is 2 bytes. Since u is a union, memory
allocated to u will be max of float y(4 bytes) and long z(8 bytes). So, total size will be 18 bytes (10 +
8).

4. The number of tokens in the following C statement.


filter_none
edit
play_arrow
brightness_4
printf("i = %d, &i = %x", i, &i);

is (GATE 2000)
(a) 3
(b) 26
(c) 10
(d) 21
Answer (c)
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.

5. The following C declarations


filter_none
edit
play_arrow
brightness_4
struct node 

   int i; 
   float j; 
}; 
struct node *s[10] ; 

define s to be (GATE CS 2000)


(a) An array, each element of which is a pointer to a structure of type node
(b) A structure of 2 fields, each field being a pointer to an array of 10 elements
(c) A structure of 3 fields: an integer, a float, and an array of 10 elements
(d) An array, each element of which is a structure of type node.
Answer: (a)

You might also like