Preprocessor Directives Dynamic Memoryallocation: #Include #Define Int Void #Ifndef #Endif
Preprocessor Directives Dynamic Memoryallocation: #Include #Define Int Void #Ifndef #Endif
Dynamic MemoryAllocation
1.
#include<stdio.h>
#define sunbeam 1998
int main( void )
{
#ifndef sunbeam
printf("sunbeam");
#endif
printf("SunBeam");
return 0;
}
A. SunBeam
B. sunbeam
C. 1998
d. sunbeam 1998
Answer: A
2.
#include<stdio.h>
#include<stdlib.h>
int main( void )
{
int *a[3];
a = (int*) malloc(sizeof(int)*3);
free(a);
return 0;
}
Answer : B
return 0;
}
A. 18
B. 27
C. 36
D. 9
Answer: B
4.
C Processor
Answer: D
A. Compliation Error
B. Error free
C. Memory Leakage
D. dangling pointer
Answer : C
6.
#include<stdio.h>
#define max 100
int main( void )
{
#ifndef max
#ifdef max
if(max)
printf("Sunbeam");
#endif
printf("Pune");
#endif
return 0;
}
A. Pune
B. sunbeam
C. sunbeamPune
D. no output
Answer: D
A. sunbeam(null)
B. sunbeam
C. Run time error
D. Compile time error
Answer: A
8.
#include<stdio.h>
#define print(Y,X) (Y/Y,X*Y)
int main( void )
{
printf("%d",print(5,9));
return 0;
}
A. 1
B. 81
C. 45
D. 0
Answer: C
return 0;
}
A. 1
B. 0
C. 4
D. 3
Answer : A
10.
#include <stdio.h>
#define int float*
int main( void )
{
int j=NULL, i=50;
return 0;
} // Note : Consider 64 bit compliation
Answer : C
return 0;
}
A. 0
B. 2
C. 3
D. 1
Answer : D
12.
#include <stdio.h>
#define print() printf("%d ",10/2)
int main( void )
{
printf("%d",print());
return 0;
}
A. 10 1
B. 2 2
C. 5 1
D. 5 2
Answer : D
return 0;
}
A. 11 2
B. 11 1
C. 11 11
D. none
Answer : A
14.
#include <stdio.h>
struct emp
{
struct emp *next;
int sal;
};
int main(void)
{
struct emp *p1 = calloc(1, sizeof(struct emp));
p1->sal = 1;
p1->next = calloc(1, sizeof(struct emp));
printf("%d\n", p1->next->sal);
return 0;
}
A. 0
B. 4
C. 8
D. 2
Answer: A
strcpy(ptr , "Demo1");
strcpy(ptr , "Demo2");
free(ptr);
return 0;
}
A. Demo1
B. Demo2
C. Demo1Demo2
D. exit value -1
Answer: D
16.
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
17.
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;
}
int *fun3 (void)
{
int *px;
px = (int *) malloc (sizeof(int));
*px= 10;
return px;
}
Answer: A