| | |
Need help figuring out C++ Pointers
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
&val means address of the varialble var
*p (if is a pointer (int *p
) means value at address pointed at by p.Changes this will change the variable it points to.
int val = 1;
p=&val;
val+=10
cout<<val<<" *p="<<*p; //output is the same for both
(*p) += 4; //changes the value of val
cout<<val<<" *p="<<*p; //output is the same for both
The outputs are:
11 11
15 15
*p (if is a pointer (int *p
) means value at address pointed at by p.Changes this will change the variable it points to.int val = 1;
p=&val;
val+=10
cout<<val<<" *p="<<*p; //output is the same for both
(*p) += 4; //changes the value of val
cout<<val<<" *p="<<*p; //output is the same for both
The outputs are:
11 11
15 15
•
•
Join Date: Aug 2004
Posts: 18
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by hfick
the next question asks says i am supposed to state the data type of each variable...
double var1, *ptr1, *ptr2;
float *ptr3;
int var2, *var4
Here's a link:Check it and see, ask if in doubt
http://www.daniweb.com/techtalkforums/thread9878.html
http://www.daniweb.com/techtalkforums/thread9878.html
•
•
•
•
Originally Posted by hfick
so what would the data type of ptr1 be? would it be just ptr1 since it doesn't have the (*) in front of it or how does that work?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Oct 2004
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by hfick
I am supposed to figure out what the output produced would be from this equation..can anyone help me and explain it to me
char var1='s';
char var2='x';
char *ptr1, *ptr2;
ptr1=&var2;
*ptr2=*ptr1;
cout << *ptr1 << " " < var2 << endl;
output will be
X X
because ptr1 point to the var2 and var2 contain value 'x';
•
•
•
•
Originally Posted by manoj9_5
-----------------------------------------------------------
output will be
X X
because ptr1 point to the var2 and var2 contain value 'x';
I'm here to prove you wrong.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Error in c++ program
- Next Thread: database access using c++
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






