C Programming - Pointers - Discussion
Discussion Forum : Pointers - Find Output of Program (Q.No. 13)
13.
What will be the output of the program?
#include<stdio.h>
int main()
{
int arr[3] = {2, 3, 4};
char *p;
p = arr;
p = (char*)((int*)(p));
printf("%d, ", *p);
p = (int*)(p+1);
printf("%d", *p);
return 0;
}
Discussion:
87 comments Page 6 of 9.
Sai said:
1 decade ago
Please explain about
p = (int*)(p+1);
printf("%d", *p);
p = (int*)(p+1);
printf("%d", *p);
Iswarya said:
1 decade ago
(int*)p+1 comes to 2nd location in an array. Then how it prints zero?
Abhishek.e.k said:
1 decade ago
p = (char*)((int*)(p));
even without this line program will run fine
even without this line program will run fine
Shivam varshney said:
8 years ago
The answer is wrong here.
The compiler will produce an error.
The compiler will produce an error.
Ankur said:
1 decade ago
@pankaj.
Dude run it on turbo c it won't give you an error.
Dude run it on turbo c it won't give you an error.
Garvita said:
1 decade ago
Why we type casted p again to char?
p=(char*)((int*)(p));
p=(char*)((int*)(p));
Murthy said:
1 decade ago
"p=arr";
Cannot convert 'int*' to 'char*' in assignment.
Cannot convert 'int*' to 'char*' in assignment.
Ishu said:
9 years ago
It will result in error, can't convert (int*) to (char*).
Akash said:
5 years ago
All droughts are cleared, Thanks for explaining @Puru.
Muhammad Imran said:
9 years ago
p = (char*)((int*)(p));
Why do this type casting?
Why do this type casting?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers