C-Pointers Question and Answer
C-Pointers Question and Answer
171. Which of the following statement is true ?
- The address of operator & requires 1value as its operand where as indirection operator (*) returns an 1value.
- the address of operator (&) returns operator (*) returns an 1value
- Both address of operator *(&) teturns an 1value where as indirection operator (*) requires an 1value
- Both address of operator (&) and indirection operator (*) requires an 1value.
172. Find the output.
void main ()
{
int *p;
const int i=10;
p=&i;
printf "%d %d", *p, ++*p);
}
void main ()
{
int *p;
const int i=10;
p=&i;
printf "%d %d", *p, ++*p);
}
- 10 11
- 11 11
- Can not modify a constant object
- None of these
173. Find the output
void main ( )
int *p;
float a[5];
for (p=a; p<&a [5]; p++)
{
*p=p-a;
printf("%d", *p);
}
}
void main ( )
int *p;
float a[5];
for (p=a; p<&a [5]; p++)
{
*p=p-a;
printf("%d", *p);
}
}
- 01234
- 0123456789
- 12345
- Error: Integer pointer can't be assigned to float array.
174. Find the output
void main ( )
{
char *p="abc123", *q="abc";
while *p++=*q++)
printf("%c%c", *p,*q);
}
void main ( )
{
char *p="abc123", *q="abc";
while *p++=*q++)
printf("%c%c", *p,*q);
}
- aabbcc
- bbcc112233
- bbcc1
- aabbcc123
175. Find the output
#include "stdio.h"
void main ( )
char *const fp);
char *const ptr;
ptr=fp( );
printf ("\n %s", ptr);
}
char *const fp( )
{
return "MAGIC";
}
#include "stdio.h"
void main ( )
char *const fp);
char *const ptr;
ptr=fp( );
printf ("\n %s", ptr);
}
char *const fp( )
{
return "MAGIC";
}
- Null pointer assignment
- Error: return "MAGIC" has to be written return ("MAGIC")
- Error:ptr=sp( ), can't modify const object
- Error:return may return a char butnot a string
176. Find the output
int a[ ] = {1, 2, 3, 4, 5}:
void main ( )
{
int *p, *q, i;
p=a;
q=a+2;
i=*p++;
printf("%d %d", i, q-p);
}
int a[ ] = {1, 2, 3, 4, 5}:
void main ( )
{
int *p, *q, i;
p=a;
q=a+2;
i=*p++;
printf("%d %d", i, q-p);
}
- 1 1
- 1 2
- 2 2
- None of these
177. Find the output
void main ( )
{
int *p [ ] = {1, 45, 78, 100};
printf("%d", sizeof (p) / sizeof (int*));
}
void main ( )
{
int *p [ ] = {1, 45, 78, 100};
printf("%d", sizeof (p) / sizeof (int*));
}
- 1
- 4
- 2
- Compilation error
178. Find the output
void main ( )
{
char *p="Tuni";
reverse (p);
printf("%s",p);
}
reverse (char *q)
{
char *r="Hello";
q=r;
printf("&s", q);
}
void main ( )
{
char *p="Tuni";
reverse (p);
printf("%s",p);
}
reverse (char *q)
{
char *r="Hello";
q=r;
printf("&s", q);
}
- Hello Hello
- Tuni
- Hello Tuni
- Invalid function cal
179. Find the output
void main ( )
{
const char *p="CIMPLE";
p++;
*p='a';
printf("%s",p);
}
void main ( )
{
const char *p="CIMPLE";
p++;
*p='a';
printf("%s",p);
}
- IMPLE
- Error:*='a', can not modify constant object
- Error:p can not be incremented.
- IMPLE and garbage
180. Find the output
void fun (int *a,int *b)
{
int *t;
t=a, a=b, b=a;
printf("%d %d", 8a, *b);
}
void main ( )
{
int a=3;
void fun ( );
int b=5;
fun (&a, &b);
}
void fun (int *a,int *b)
{
int *t;
t=a, a=b, b=a;
printf("%d %d", 8a, *b);
}
void main ( )
{
int a=3;
void fun ( );
int b=5;
fun (&a, &b);
}
- 3 5
- 3 3
- 5 5
- Compilation error