C-Pointers Question and Answer
C-Pointers Question and Answer
201. Find the output
void main ( )
{
int a=5, b=7;
int *p;
p=&a;
p--;
*p=10;
printf("%d %d", a, b);
}
void main ( )
{
int a=5, b=7;
int *p;
p=&a;
p--;
*p=10;
printf("%d %d", a, b);
}
- 5 7
- 5 10
- 10 7
- Garbage 7
202. What is major difference between malloc and calloc ?
- Malloc initializes it memory location with garbage but calloc initializes with 0
- Malloc memory allocation is single dimensional array equivalent and calloc memory allocation is double dimensional array equivalent
- Malloc takes only one parameter but calloc takes two parameter
- None of these
203. Find the output
void main ( )
{
char *s1="alpha", *s2="alpha";
if (!strcmp (s1, s2))
printf("%d", *s1+*s2);
}
void main ( )
{
char *s1="alpha", *s2="alpha";
if (!strcmp (s1, s2))
printf("%d", *s1+*s2);
}
- 97
- 194
- Garbage
- Compilation eror
204. After we free an allocated memory block using free (), the pointer will become
- Null pointer
- Danging pointer
- Wild pointer
- Smart pointer
205. Consider the following declarations:
int a[10];
int *p=a;
Which amot the following is portable way to print value of pointer p?
int a[10];
int *p=a;
Which amot the following is portable way to print value of pointer p?
- printf ("%u\n", *p);
- printf("%d\n", p);
- printf("%1u",p);
- printf("%p\n", (void*);
206. Find the output
int man ()
{
char *cp=NULL;
{
char c;
cp=&c;
}
return 0;
}
After the execution of above inner block
int man ()
{
char *cp=NULL;
{
char c;
cp=&c;
}
return 0;
}
After the execution of above inner block
- Pointer cp is dead
- Pointer cp is still alive and is dangling pointer
- Pointer cp is dead and again points to NULL
- Pointer cp is alive and acessing it will error.
207. Modifying the object's value pointed by dangling pointer can cause
I. Change in object's value unexpectedly
II. Memory corruption
III. Null pointer assinment
IV. Error: Constant object can't modidy
I. Change in object's value unexpectedly
II. Memory corruption
III. Null pointer assinment
IV. Error: Constant object can't modidy
- Only (i) is true
- Only (iii) is true
- Both (i) and (ii) is true
- Both (ii) and (iv) is true.
208. Find the output
void main ( )
{
int *p, *q;
p=(float *) 2000;
q=(char *) 3000;
printf("%d", q-p);
}
void main ( )
{
int *p, *q;
p=(float *) 2000;
q=(char *) 3000;
printf("%d", q-p);
}
- 500
- 1000
- 2000
- Compilation Error
209. Find the output
void main ()
{
int *p = (int *)50;
int *q;
q=p+5;
printf("%c", (q-p) + 62);
}
void main ()
{
int *p = (int *)50;
int *q;
q=p+5;
printf("%c", (q-p) + 62);
}
- graphic char
- char A
- Char C
- Err: illegal pointer airthametic
210. What is true about the following statement
typedef int (*mass) (char*, char*);
mass m1, m2;
typedef int (*mass) (char*, char*);
mass m1, m2;
- m1 and m2 are pointers to function that accept two char pointers and returns an int
- m1 and m2 are not defined
- mass is a function returning int whih points to two char
- Declaration error