abhijeets7663@gmail.com
help@ccatcracker.in

Section B Question



76.   

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);
}


A.   2, 8
B.   4, 8
C.   2, 4
D.   4, 12

                  

D

Because float i; ---> 'i' is a float variable.

Hence size of float is 4 bytes.

Here from fun(2,3)the value of a and b is 2,3&s value is 2
a*b*s=2*3*2=12



75.   

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;
}


A.   4, 4, 4
B.   2, 2, 2
C.   2, 8, 4
D.   2, 4, 8

                  

A
Any pointer holds 4 bytes of memory in gcc compiler.



74.   

What will be the output of the program?

#include<stdio.h>

int main()
{
char far *near *ptr1;
char far *far *ptr2;
char far *huge *ptr3;
printf("%d, %d, %d\n", sizeof(ptr1), sizeof(ptr2), sizeof(ptr3));
return 0;
}


A.   4, 4, 8
B.   4, 4, 4
C.   2, 4, 4
D.   2, 4, 8

                  

C

Near pointers-refer to current segment $ point to 64kbytes, occupy 2bytes.

Far pointer-refer to data segment $ points to gigabyte, occupy 4 byte.

Huge pointer-similar to far pointers, but work slowpy, occupy 4 byte.



73.   

What will be the output of the program?

#include<stdio.h>
#include<stdlib.h>

int main()
{
union test
{
int i;
float f;
char c;
};
union test *t;
t = (union test *)malloc(sizeof(union test));
t->f = 10.10f;
printf("%f", t->f);
return 0;
}


A.   10
B.   Garbage value
C.   10.100000
D.   Error

                  

C

Since t->f=10.10f it gives the output as 10.100000
as it float takes 6 digits after the decimal point.



72.   

What will be the output of the program (16-bit platform)?

#include<stdio.h>
#include<stdlib.h>

int main()
{
int *p;
p = (int *)malloc(20);
printf("%d\n", sizeof(p));
free(p);
return 0;
}


A.   4
B.   2
C.   8
D.   Garbage

                  

B

Here P is integer pointer used for storing the address
and address is always 2 bytes hence sizeof P is 2 bytes.



71.   

What will be the output of the program?

#include<stdio.h>
#include<stdlib.h>

int main()
{
int *p;
p = (int *)malloc(20); /* Assume p has address of 1314 */
free(p);
printf("%u", p);
return 0;
}


A.   1314
B.   Garbage value
C.   1316
D.   Random address

                  

A
actually p holds the starting address of the array.......
free funtion will delete the memory which is allocated for that array.
say array is of size 10 and it is of integer type so it should require 20
bytes of memory as "int" occupies 2 bytes of memory (ofcourse it
depends on compiler). So when we free the pointer it doesn't mean
that we are deleting the pointer . We are deleting the memory which
is allocated to the pointer i.e, 20 bytes of memory
(according to my example).........so p has the address 1314 itself.



70.   

What will be the output of the program?

#include<stdio.h>

int main()
{
typedef float f;
static f *fptr;
float fval = 90;
fptr = &fval;
printf("%f\n", *fptr);
return 0;
}


A.   90.000000
B.   9
C.   0
D.   90

                  

A

The pointer fptr contains the address where the value 90
is stored and in the printf statement we have printed it out
using the format specifier for float %f hane 90 with six places
after the decimal point gets get printed.



69.   

In the following code what is 'P'?

typedef char *charp;
const charp P;


A.   P is a constant
B.   P is a character con
C.   P is character type
D.   None of above

                  

P is a pointer to a constant.

Because,

Const char *p;.



68.   

What will be the output of the program?

#include<stdio.h>
int main()
{
char str[]="C-program";
int a = 5;
printf(a >10?"Ps\n":"%s\n", str);
return 0;
}


A.   C-program
B.   Ps
C.   Error
D.   None of above

                  

Step 1: char str[]="C-program"; here variable str contains "C-program".
Step 2: int a = 5; here variable a contains "5".
Step 3: printf(a >10?"Ps\n":"%s\n", str); this statement can be written as

if(a > 10)
{
printf("Ps\n");
}
else
{
printf("%s\n", str);
}
Here we are checking a > 10 means 5 > 10.
Hence this condition will be failed. So it prints variable str.

Hence the output is "C-program".



67.   

How many times the while loop will get executed if a short int is 2 byte wide?

#include<stdio.h>
int main()
{
int j=1;
while(j <= 255)
{
printf("%c %d\n", j, j);
j++;
}
return 0;
}


A.   255
B.   265
C.   266
D.   Infinite

                  

The while(j <= 255) loop will get executed 255 times. The size short int(2 byte wide) does not affect the while() loop.



Enter Email If You are new here So You will get Daily Notification Dont Forget any single Question:

E-mail: