By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 804 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

pointer

P: 63
what is the meaning of this

(char *) ∫
Jun 21 '07 #1
Share this Question
Share on Google+
3 Replies


Expert 10K+
P: 11,448
what is the meaning of this

(char *) ∫
Nothing; it's incorrect C/C++. If you had done this instead:

Expand|Select|Wrap|Line Numbers
  1. T v;
  2. (char*)&v;
  3.  
the meaning would be this: the address of an identifier 'v' of type 'T' is cast to
a char pointer.

kind regards,

Jos
Jun 21 '07 #2

P: 63
thanks...please say me whether I have understood it correctly

main() {
int var=68;
char* ptr;
ptr=(char * )&var;
printf("%s",ptr);

}

by typecasting , iam making the pointer "ptr " to point to variable "var"
Jun 21 '07 #3

weaknessforcats
Expert Mod 5K+
P: 9,197
var is an int. &var is the address of an int. If you try to use &var as a pointer to a char, the compiler will produce an error. The cast does not change var. All it does is lie to the compiler that var is a char. Using &var as a char* will now corrupt the int.

I assume you are learning C. My advice is to not cast, ever, unless your are forced into it. Any cast is a direction from you to the compiler to override the rules of the language.

Be careful.
Jun 21 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.