Difference of char * and int *
-
Hi, I would like to ask that;
#include "stdafx.h" #include int _tmain() { int myInts[3] = {0,1,2}; char * myName = "sarp"; std::cout << myName << std::endl; std::cout << myInts << std::endl; return 0; }
Why it prints out sarp in first output and memory location in second output? I was waiting for memory location of s in the first one. Also, what is the difference between;char * myName = "sarp"; char myName[] = "sarp";
Thanks, Sarp - When in doubt, push a pawn! - -
Hi, I would like to ask that;
#include "stdafx.h" #include int _tmain() { int myInts[3] = {0,1,2}; char * myName = "sarp"; std::cout << myName << std::endl; std::cout << myInts << std::endl; return 0; }
Why it prints out sarp in first output and memory location in second output? I was waiting for memory location of s in the first one. Also, what is the difference between;char * myName = "sarp"; char myName[] = "sarp";
Thanks, Sarp - When in doubt, push a pawn! -cout must have an overloaded method to output char*, and nothing to output int* ( except for the adress ).
Maximilien Lincourt Your Head A Splode - Strong Bad
-
Hi, I would like to ask that;
#include "stdafx.h" #include int _tmain() { int myInts[3] = {0,1,2}; char * myName = "sarp"; std::cout << myName << std::endl; std::cout << myInts << std::endl; return 0; }
Why it prints out sarp in first output and memory location in second output? I was waiting for memory location of s in the first one. Also, what is the difference between;char * myName = "sarp"; char myName[] = "sarp";
Thanks, Sarp - When in doubt, push a pawn! -kromozom wrote: Why it prints out...memory location in second output? What would you expect it to print out? kromozom wrote: I was waiting for memory location of s in the first one. Then you should use
cout << &myName << endl;
instead.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
Hi, I would like to ask that;
#include "stdafx.h" #include int _tmain() { int myInts[3] = {0,1,2}; char * myName = "sarp"; std::cout << myName << std::endl; std::cout << myInts << std::endl; return 0; }
Why it prints out sarp in first output and memory location in second output? I was waiting for memory location of s in the first one. Also, what is the difference between;char * myName = "sarp"; char myName[] = "sarp";
Thanks, Sarp - When in doubt, push a pawn! -;)well.....for thiz iz for ur info..... whenu declare the variable say.....
char a[10];
here the variable "a" is bacially like a pointer,it terminates only when it "sees" the "\O" thatz why u dont get the same answer..... if want just one letter to come do like thiz..... cout<<*(myname); if u want the second letter..... cout<<*(myname+1) and so on..... hope that helpz..... happy programmin..... cheerz..... :-D
-
;)well.....for thiz iz for ur info..... whenu declare the variable say.....
char a[10];
here the variable "a" is bacially like a pointer,it terminates only when it "sees" the "\O" thatz why u dont get the same answer..... if want just one letter to come do like thiz..... cout<<*(myname); if u want the second letter..... cout<<*(myname+1) and so on..... hope that helpz..... happy programmin..... cheerz..... :-D