Assigning (String + Integer) to Variable : C Programming
In this typical question we are assigning (String + Integer) to variable of type character pointer. In this case starting address of the substring will be returned as a result.
Assigning (String + Integer) to Variable
Now guess the output of the following program
#include<stdio.h> #include<string.h> void main() { char *str=1+"Pritesh"; printf(str+1); }
Options :
- Pritesh
- ritesh
- itesh
- Incorrect Declaration
Output:
Switch to String MCQ Home : Click Here
How and Why ?
- *str is Pointer Variable and AddressOf(1+”Pritesh”) is Assigned to Pointer Variable
- It Tells that Address of “r” is Assigned as “Starting / Base Address”
- Refer : Here to Learn How to Solve printf(1+”%d”) type Problems ?.
- So Initially “ritesh” is Assigned to String Type Variable.
*str = "ritesh"
- Before Printing “str + 1″ prints “itesh”