Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: difference between casting and atol,atoi functions

Reply
Thread Tools

Re: difference between casting and atol,atoi functions

 
 
Olaf
Guest
Posts: n/a
 
      02-15-2005
Hello

statement 1:
the pointer value is casted to a pointer to a long
wher the pointer directs to is the array of char, a long is 4 byte
it gives *x = 0xFFFFFFFF

statment 2:
atol has only 1 parameter, a string
char 255 is not a number in the ascii table
so y = 0;

if you put
buf[0]='1'; // 0x31
buf[1]='2'; // 0x32
buf[2]='3'; // 0x33
buf[3]='4'; // 0x34
buf[4]='\0';

atol(buf) => 1234
x = (long *)buf;
x is the adres of buf
*x => 0x31323334 => 825373492

so the diference is huge.

Greetings Olaf

"Janice" <(E-Mail Removed)> wrote in message news:<cuccv5$(E-Mail Removed)>...
> unsigned char buf[255];
> signed long* x;
> signed long y;
> buf[0]=255;
> buf[1]=255;
> buf[2]=255;
> buf[3]=255;
> //statment 1
> x=(signed long*)buf;
> //statement 2
> y=atol(buf,4);
>
> What is the difference between statement 1 and 2?
> Thanx

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between typecasting and casting Nishu C Programming 6 02-17-2007 12:06 PM
difference between toString() and type casting a n Object to String narsing Java 2 10-23-2006 07:24 AM
Difference between casting by as and normal cast =?Utf-8?B?UmFlZCBTYXdhbGhh?= ASP .Net 2 08-15-2005 04:00 PM
Difference between bin and obj directories and difference between project references and dll references jakk ASP .Net 4 03-22-2005 09:23 PM
Re: difference between casting and atol,atoi functions infobahn C Programming 1 02-15-2005 08:09 AM



Advertisments