05 Preprocessor Directives and Dynamic Memory AllocationWithAnswers Updated 1
05 Preprocessor Directives and Dynamic Memory AllocationWithAnswers Updated 1
Dynamic MemoryAllocation
1.
#include <stdio.h>
void fun();
int main( void )
{
fun();
return 0;
}
void fun()
{
#ifndef value
#define value 100
#undef value
#else
#undef value
#define value 200
#endif
#define Value 300 printf("Value : %d",Value);
return ;
}
A. Value : 100
B. Value : 200
C. no output
D. Compile time error
E. Value : 300
Answer: C
2.
#include<stdio.h>
#line 100
int main( void )
{
printf("\n line = %d ",__LINE__ );
#line 0
printf(" line = %d ",__LINE__ );
#line 100
printf(" line = %d ",__LINE__ );
return 0;
}
Answer: C
3.
#include<stdio.h>
#include<string.h>
int main( void )
{
#define SUNBEAM "SUNBEAM IT PARK \n"
#define Sunbeam "SUNBEAM MARKETYARD\n"
#ifdef SUNBEAM
printf(SUNBEAM);
#endif
#ifdef SUNBEAM
printf(Sunbeam);
#endif
printf("\'Sunbeam\'\n");
printf("\"SUNBEAM\" \n");
return 0;
}
A. SUNBEAM IT PARK
B. SUNBEAM IT PARK
SUNBEAM MARKETYARD
Sunbeam
SUNBEAM
C. SUNBEAM IT PARK
SUNBEAM MARKETYARD
'Sunbeam'
"SUNBEAM"
D. SUNBEAM MARKETYARD
Answer: C
A. 1
B. 625
C. 75
D. 225
Answer: A
4.
#include <stdio.h>
#define MACRO(n, i, a, m) m##a##i##n
#define MAIN MACRO(n, i, a, m)
printf("\"SUNBEAM\"");
return 0;
}
A. "SUNBEAM"
B. SUNBEAM
C. sunbeam
D. compile time error
Answer: A
A. X=0,Y=0
B. X=10,Y=20
C. X=20,Y=10
D. Compile time error
Answer: A
6.
#include<stdio.h>
#define exp(a) a+a * 5 / a*a
int main( void )
{
int x = exp(3+2) * 5;
printf("Value of X=%d",x);
return 0;
}
A. Value of X=27
B. Value of X=32
C. Value of X=20
D. compile time error
Answer: A
A. sizeof(i)=8 sizeof(j)=1
B. sizeof(i)=4 sizeof(j)=1
C. sizeof(i)=8 sizeof(j)=8
D. sizeof(i)=4 sizeof(j)=4
Answer: B
8.
#include <stdio.h>
#define INCREMENT(x) --x
#define DECREMENT(x) ++x
int main( void )
{
char *ptr = "SunbeamKarad";
int x = 10;
printf("%s", DECREMENT(ptr));
printf("%3d\t",DECREMENT(x));
printf("%s", INCREMENT(ptr));
printf("%3d", INCREMENT(x));
return 0;
}
A. unbeamKarad 11 SunbeamKarad 10
B. SunbeamKarad 11 unbeamKarad 10
C. garbage value SunbeamKarad 11 SunbeamKarad 10
D. garbagevalue SunbeamKarad 9 SunbeamKarad 10
Answer: A
10.
#include<stdio.h>
#include<string.h>
int main(void)
{
char joining1[10]="",joining2[10]="",joining3[10]="";
strcat(joining1,"TIME");
strcat( joining1,"_"); strcat( joining1,"_");
strcat( joining3,joining1);
strcat( joining2,"_"); strcat( joining2,"_");
strcpy( joining1,joining2);
strcat( joining1,joining3);
printf("\n time= %s", joining1);
return 0;
}
A. time= __TIME__
b. time= current time will print
c. compile time error
D. run time error
Answer: A
Answer: D
Answer: A
A. K
B. k
C. s
D. S
Answer: B
14.
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
char *ptr=NULL;
strcpy(ptr , "Demo1");
strcpy(ptr , "Demo2");
free(ptr);
printf("%s\n",ptr);
return 0;
}
Answer: D
15.
what type of data u can store in this block of memory?
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
void *ptr=NULL;
ptr = malloc(10);
return 0;
}
A. int
B. char
C. float
D. all of above data types
Answer: D
16.
Which of the above three functions are likely to cause
problems with pointers?
int * fun1 (void)
{
int x= 10;
return (&x);
}
int * fun2 (void)
{
int * px;
*px= 10;
return px;
}
Answer: A