Redian新闻
>
C, how is a string cast into a int?
avatar
C, how is a string cast into a int?# Programming - 葵花宝典
M*m
1
char *a = "12";
int j = (int)a;
j is 134514482, what is going on here? how does c convert "12" to this
number?
avatar
M*m
2
is 134514482 the address of a?

【在 M*m 的大作中提到】
: char *a = "12";
: int j = (int)a;
: j is 134514482, what is going on here? how does c convert "12" to this
: number?

avatar
P*e
3
int j = atoi(a);

char *a = "12";
int j = (int)a;
j is 134514482, what is going on here? how does c convert "12" to this
number?

【在 M*m 的大作中提到】
: char *a = "12";
: int j = (int)a;
: j is 134514482, what is going on here? how does c convert "12" to this
: number?

avatar
M*m
4
Looks like j is the address of the string. but here is another problem.


int main(){

char *a = "12";

int t = (int)a;

printf ("%d\n", t);

printf("%c\n", *((char *)t

【在 P********e 的大作中提到】
: int j = atoi(a);
:
: char *a = "12";
: int j = (int)a;
: j is 134514482, what is going on here? how does c convert "12" to this
: number?

avatar
M*m
5
Oops, just found the problem. never mind, it is the address.







【在 M*m 的大作中提到】
: Looks like j is the address of the string. but here is another problem.
:
:
: int main(){
:
: char *a = "12";
:
: int t = (int)a;
:
: printf ("%d\n", t);

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。