-
With every use of a memory allocation function, what function should be used to release allocated memory which is no longer needed?
- unalloc()
- dropmem()
- dealloc()
- free()
-
void *ptr; myStruct myArray[10]; ptr = myArray;
Which of the following is the correct way to increment the variable "ptr"?- ptr = ptr + sizeof(myStruct);
- ++(int*)ptr;
- ptr = ptr + sizeof(myArray);
- ptr = ptr + sizeof(ptr);
- main()
{ char *ptr = ” Hi How r U?”;
*ptr++; printf(“%s\n”,ptr); ptr++; printf(“%s\n”,ptr);
}
- Empty string
- Compile error
- Hi How r U?
i How r U?
- Hi How r U? Hi How r U?
- Empty string
-
int testarray[2][2][2] = {11, 22, 33, 44, 55, 66, 77, 88};
What value does testarray[1][1][0] in the sample code above contain?
- 55
- 77
- 88
- 11
- int a=10,b; b=a++ + ++a;
printf("%d,%d,%d,%d",b,a++,a,++a);
what will be the output when following code is executed- 12,10,11,13
- 22,10,11,13
- 22,11,11,11
- 22,13,13,13
- When reallocating memory if any other pointers
point into same piece of memory do these pointers-
- need to be readjusted
- they get readjusted automatically
- C does it on behalf of user
- none of above
- Which of these are correct method of declaring
pointer?
- char *p,
- char* p,
- char * p,
- char*p.
- I only
- I and II
- I, II and III
- all of above
- What is the output of this code
main()
{ int c[ ]={2.8,3.4,4,6.7,5};
int j,*p=c,*q=c;
for(j=0;j<5;j++)
{ printf(" %d ",*c);
++q; }
for(j=0;j<5;j++)
{ printf(" %d ",*p);
++p;
}
}- 2 2 2 2 2 2 3 4 6 5
- 2 2 2 2 2 3 4 6 5
- 2 2 2 2 3 4 6 5
- 2 2 2 2 3 4 6 5
- What will be the output of following code
Int main(void)
{ int *p =NULL;
int *c =(int*)malloc(sizeof(p));
printf(" %0x" &c);
return 0;
}- Some address
- Blank Screen
- Some integer value
- Garbage value
- What is the output of the following program?
void main()
{ int *ptr =55;
clrscr();
printf("%d", ++(ptr));
}- 54
- 55
- 56
- some address
- Find the output for the following C programr
main()
{ char *ptr = "Ramco Systems";
*ptr++;
printf("%sn",ptr);
ptr++;
printf("%sn",ptr);
}
a. Ramco Systemsnamco Systemsn
b. Ramco systems
c. amco Systems
d. Empty string - main()
{
int a,b,result;
printf("nEnter the numbers to be multiplied :");
scanf("%d%d",&a,&b);
result=0;
while(b != 0)
{
if (b&01)
result=result+a;
a<<=1;
b>>=1;
} printf("nResult:%d",result);
}
For a=8 & b=6 what will be the output
- 68
- 86
- 48
- 84
- Between a long pointer and a char pointer , which
one consumes more memory?
- long pointer
- Char pointer
- Both will occupy same memory
- None of above
- main()
{ int a[]={2,4,6,8,10};
int i;
change(a,5);
for(int i=0;i<=4;i++)
printf("\n %d", a[i]);
}
change(int *b,int n)
{ int i;
for(i=0;i<n;i++)
*(b+i) = *(b+i)+5;
}
Output will be
- 2,4 6,8 10
- 7,9,11,13,15
- 5,7,9,11,13
- 3,5,7,9,11
- main()
{ int i;
float *pf;
pf = (float *)&i; *pf = 100.00;
printf("n %d", i);}
- Some Integer not 100
- 100
- Runtime error.
- 0
- main()
{ int i, j, *p;
i = 25;
j = 100;
p = &i;
printf("%f", i/(*p) );
}
- Compile erro
- 1.00000
- Runtime error.
- 0.00000
- main()
{
int i, j;
scanf("%d %d"+scanf("%d %d", &i, &j));
printf("%d %d", i, j);
}
- Compile error
- 0, 0
- Runtime error.
- the first two values entered by the user.
- struct Foo
{ char *pName;
};
main()
{
struct Foo *obj = malloc(sizeof(struct Foo));
clrscr();
strcpy(obj->pName,"Your Name");
printf("%s", obj->pName);
}- Name
- compile error
- Your Name
- Runtime error
- In the following code, in which order the
functions would be called?
x = f1(23,14)*f2(12/4)+f3();
- f1, f2, f3
- f3, f2, f1
- The order may vary from compiler to compiler
- None of the above
- What is the equivalent pointer expression for
referring the same element a[i][j][k][l]?
- *(*(*(*(a+l)+k)+j))
- *(*(*(*(a+i)+j)+k)+l)
- *(*(*(*(a+l)+k)+j)i)
- None of the above
Answers-
| 1-d | 2-b | 3-c | 4-b | 5-d | 6-a | 7-d | 8-a | 9-a | 10-d |
| 11-a | 12-c | 13-c | 14-b | 15-a | 16-a | 17-d | 18-c | 19-a | 20-b |
No comments:
Post a Comment