Sail E0 Webinar

MCQs

Total Questions : 35 | Page 2 of 4 pages
Question 11.


Point out the error in the following program.


#include<stdio.h>
#include<stdlib.h>
int main()
{
static char *p = (char *)malloc(10);
return 0;
}
  1.    Error: Lvalue required
  2.    Error: Rvalue required
  3.    Error: invalid *p declaration
  4.    No error
 Discuss Question
Answer: Option D. -> No error


Question 12.


Point out the error in the following program (in Turbo C under DOS).


#include<stdio.h>
union emp
{
int empno;
int age;
};
int main()
{
union emp e = {10, 25};
printf("%d %d", e.empno, e.age);
return 0;
}
  1.    Error: Lvalue required
  2.    Error: Rvalue required
  3.    Error: cannot initialize more than one union member.
  4.    No error
 Discuss Question
Answer: Option C. -> Error: cannot initialize more than one union member.


Question 13.


What will be the output of the program?


#include<stdio.h>
int main()
{
struct s1
{
char *z;
int i;
struct s1 *p;
};
static struct s1 a[] = {{"Nagpur", 1, a+1} , {"Chennai", 2, a+2} ,
{"Bangalore", 3, a} };
struct s1 *ptr = a;
printf("%s,", ++(ptr->z));
printf(" %s,", a[(++ptr)->i].z);
printf(" %s", a[--(ptr->p->i)].z);
return 0;
}
  1.    Nagpur, Chennai, Bangalore
  2.    agpur, hennai, angalore
  3.    agpur, Chennai, angalore
  4.    agpur, Bangalore, Bangalore
 Discuss Question
Answer: Option D. -> agpur, Bangalore, Bangalore


Question 14.


What will be the output of the program in Turbo C?


#include<stdio.h>
int main()
{
char near *near *ptr1;
char near *far *ptr2;
char near *huge *ptr3;
printf("%d, %d, %d\n", sizeof(ptr1), sizeof(ptr2), sizeof(ptr3));
return 0;
}
  1.    4, 4, 8
  2.    4, 4, 4
  3.    2, 4, 8
  4.    2, 4, 4
 Discuss Question
Answer: Option D. -> 2, 4, 4


Question 15.


What will be the output of the program?


#include<stdio.h>
int main()
{
char huge *near *ptr1;
char huge *far *ptr2;
char huge *huge *ptr3;
printf("%d, %d, %d\n", sizeof(ptr1), sizeof(ptr2), sizeof(ptr3));
return 0;
}
  1.    4, 4, 8
  2.    2, 4, 4
  3.    4, 4, 2
  4.    2, 4, 8
 Discuss Question
Answer: Option B. -> 2, 4, 4


Question 16.


What will be the output of the program under DOS?


#include<stdio.h>
int main()
{
char huge *near *far *ptr1;
char near *far *huge *ptr2;
char far *huge *near *ptr3;
printf("%d, %d, %d\n", sizeof(ptr1), sizeof(**ptr2), sizeof(ptr3));
return 0;
}
  1.    4, 4, 4
  2.    4, 2, 2
  3.    2, 8, 4
  4.    2, 4, 8
 Discuss Question
Answer: Option B. -> 4, 2, 2


Question 17.


What will be the output of the program?


#include<stdio.h>
typedef void v;
typedef int i;
int main()
{
v fun(i, i);
fun(2, 3);
return 0;
}
v fun(i a, i b)
{
i s=2;
float i;
printf("%d,", sizeof(i));
printf(" %d", a*b*s);
}
  1.    2, 8
  2.    4, 8
  3.    2, 4
  4.    4, 12
 Discuss Question
Answer: Option D. -> 4, 12


Question 18.


What will be the output of the program?


#include<stdio.h>
int main()
{
char huge *near *far *ptr1;
char near *far *huge *ptr2;
char far *huge *near *ptr3;
printf("%d, %d, %d\n", sizeof(ptr1), sizeof(*ptr2), sizeof(**ptr3));
return 0;
}
  1.    4, 4, 4
  2.    2, 4, 4
  3.    4, 4, 2
  4.    2, 4, 8
 Discuss Question
Answer: Option A. -> 4, 4, 4


Question 19.


What will be the output of the program in DOS (Compiler - Turbo C)?


int main()
{
(int)(float)(char) i;
printf("%d",sizeof(i));
return 0;
}
  1.    4
  2.    8
  3.    16
  4.    22
 Discuss Question
Answer: Option B. -> 8


Question 20.


What will be the output of the program?


#include<stdio.h>
typedef unsigned long int uli;
typedef uli u;
int main()
{
uli a;
u b = -1;
a = -1;
printf("%lu, %lu", a, b);
return 0;
}
  1.    4343445454, 4343445454
  2.    4545455434, 4545455434
  3.    4294967295, 4294967295
  4.    Garbage values
 Discuss Question
Answer: Option C. -> 4294967295, 4294967295

The system will treat the negative numbers with 2's complement method.

For 'long int' system will occupy 4 bytes (32 bits).

Therefore,

Binary 1 : 00000000 00000000 00000000 00000001

To represent -1, system uses the 2's complement value of 1. Add 1 to the 1's complement result to obtain 2's complement of 1.

So, First take 1's complement of binary 1 (change all 0s to 1s and all 1s to 0s)

1's complement of Binary 1:

11111111 11111111 11111111 11111110

2's complement of Binary 1: (Add 1 with the above result)

11111111 11111111 11111111 11111111


In HexaDecimal

11111111 11111111 11111111 11111111 = FFFF FFFF FFFF FFFF

In Unsigned Integer

11111111 11111111 11111111 11111111 = 4294967295.


Latest Videos

Latest Test Papers