Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

pointer in c

+4 votes
asked Aug 8, 2018 by anonymous
Assuming all header files are included what is the output?

.......................................................................................................

void main()

{

int*p;

*p=1;

printf("%d",*p);

}

..................................................................

why the output of above lines is 1??????????????

18 Answers

+1 vote
answered Aug 9, 2018 by anonymous
we use only &,* in pointers.   * ==>value at;  &==>address of

*p=>value at p is 1. So output is 1
0 votes
answered Aug 9, 2018 by Ritesh Srivastava (180 points)
*p stores address only and u have not specified whether the 1 is address or value
0 votes
answered Aug 15, 2018 by anonymous
bcz you have assign the value 1 to the *p (as the assignment operator follow right to left operation) it will assign value 1 to the *p variable.
commented Aug 16, 2018 by anonymous
not to variable, but to address which is pointed by p variable. in fact p variable is not initialized at all (stack) and could be random number. the assigment *p could done successfull, but it is not guaranted. back to the question... due to compiler optimalisation? printing the p variable address gives the 0. but if we manually assign that address, we get with segmentation faults. so if we cannot assign address zero (which is zero if we printing it in above example, the compiler should make some optimalisations).
0 votes
answered Aug 25, 2018 by Nitin (140 points)
Explain why not?
0 votes
answered Aug 25, 2018 by Md. Mahmudul Hasan 181-15-10679 (140 points)

out is=1 because this program asking what is *ptr value.so we know *ptr is called ....

           *p=>value at p is 1. So output is 1.

0 votes
answered Aug 25, 2018 by MEDA VEERA MANIKANTA (150 points)
answer is 1 because pointer takes the value of 1 and prints while *p
0 votes
answered Aug 26, 2018 by Sharath gowda (140 points)
answer is 1

becuase if we try to assign like this a=1 & p=&a only address will be assigned instead of we are dierctly assigning value to the pointer variable.
0 votes
answered Aug 26, 2018 by anonymous
Bcoz we are printing answer as the address of p.
0 votes
answered Sep 4, 2018 by TechnicalSeek

p is pointer variable. * indicates value at address, so printing *p gives the result as 1.

Read pointers in c 

+1 vote
answered Sep 4, 2018 by anonymous
correct question should be: "why the hell there is no segmentation fault?" :)
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...