#include
#include
int main(){
char *ptr1 = NULL;
char *ptr2 = 0;
strcpy(ptr1,"jay");
strcpy(ptr2,"sanghvi");
printf("\n%s %s",ptr1,ptr2);
return 0;
}
Explanation:
Turbo C++ 3.0: (null) (null)
Turbo C ++4.5: Run time error
Linux GCC: Run time error
Visual C++: Run time error
We cannot assign any string constant in null pointer by strcpy function.
2)What will be output of following program?
#include
int main(){
int a = 10;
void *p = &a;
int *ptr = p;
printf("%u",*ptr);
return 0;
}
ANS:-10
Void pointer can hold address of any data type without type casting. Any pointer can hold void pointer without type casting.
No comments:
Post a Comment