main
{
char *x = NULL;
printf("%c", *x);
}
Example
- NULL
- Compile error
- Runtime error
The correct option is (c).
Explanation:
In the program x points the NULL address. It is invalid to access the NULL address hence the program gives Runtime error.
Therefore the output of the program is Runtime error.
## 17) Is this a right way for NULL pointer assignment?
int j=0;
char p=(char)j;
Example
The correct option is (b).
Explanation:
The above null pointer assignment method is incorrect.
The correct way is:
char p=0 (or) char p=(char*)0
Example
## 18) Will the program be compiled in Turbo C?
include<stdio.h>
int main
{
int b=10, *i;
void *p;
i=p=&b;
i++;
p++;
printf("%u %u\n",i, p);
return 0;
}
Example
The correct option is (b).
Explanation:
In statement p++ error occur because we cannot perform arithmetic operation on void pointers.
The following error is display on compiling the above program in TurboC.
Compiling PROGRAM.C:
Error PROGRAM.C 8: Size of the type is unknown or zero.
## 19) Which statement is correct about the program given below?
include<stdio.h>
int main
{
int j=10;
int *i=&j;
return 0;
}
Example
- j is a pointer to an int and stores address of i
- i is a pointer to a pointer to an int and stores address of j
- i and j are pointers to an int
- i is a pointer to an int and stores address of j
The correct option is (d).
Explanation:
In program 'i' is the variable contain pointer. So it is pointer variable and points toward an integer type in memory location. Therefore 'i' is a pointer to an int.
Now the address of 'j' is assigned to the 'i' pointer, i.e. address of 'j' store to 'i' location.
Therefore the 'i' is a pointer to an int and it stores the address of 'j'.
## 20) What will be the output of the program given below?
include<stdio.h>
main
{
char *p= "Xyz";
while(*p)
printf("%c", *p++);
}
Example
- Runtime error
- Compile error
The correct option is (a).
Explanation:
In programming, a while loop will iterate as long as *s is not equal to '\0'. Within the loop, the character is retrieved before incrementing the address.
Thus, executing the print statement printf("%c", *p++); will display the characters Xyz as output.