New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

C++/ C question


Post Reply New Thread Subscribe

 
Thread Tools
njdevilfan26

 
Member Since: Jan 27, 2009
Posts: 8
njdevilfan26 is on a distinguished road

njdevilfan26 is offline
What is the output of the following if its command line arguments were: sample 1 5 7

Main(int argc, char *argv[]) {
Int x;
X = argv [1] + argv [2] + argv [3];
Printf (%d, x);
}

I'm not sure what the argv[1] etc... does so does anyone know the output?
QUOTE Thanks
mystic_fm

 
Member Since: Mar 15, 2007
Posts: 161
mystic_fm will become famous soon enough
Mac Specs: 17" MacBook Pro, 2.33GHz C2D, 2GB RAM

mystic_fm is offline
First off, "X" != "x", "Int" is not a defined type, "Printf" isn't a library function, etc. C is case sensitive; this won't even compile.

Even if these compile errors were fixed, the code would end up adding together three character pointer values (i.e., addresses of places in the computer's memory), the sum of which may not even fit into an integer type, and in any event is certainly not going to yield a meaningful integer sum. It most certainly is NOT adding together the integer representations of the command line arguments (1 + 5 + 7 == 13), which is apparently what the programmer was hoping for.

(By the way, argv[1] is addressing element #1 of a array named "argv". Element #1 is the index for the 2nd array element, since C arrays start at index 0.)
QUOTE Thanks
njdevilfan26

 
Member Since: Jan 27, 2009
Posts: 8
njdevilfan26 is on a distinguished road

njdevilfan26 is offline
thank you very much
QUOTE Thanks
njdevilfan26

 
Member Since: Jan 27, 2009
Posts: 8
njdevilfan26 is on a distinguished road

njdevilfan26 is offline
also I dont care about errors but can anyone explain this

Main() {
Unsigned int x = 0xffff;
~x;
Printf (“%x”, x);
}
{

what is 0xffff? and i know that ~ means one complement but what does it mean when ~x is printed?
QUOTE Thanks
deer dance

 
deer dance's Avatar
 
Member Since: Jan 23, 2009
Location: Indiana
Posts: 162
deer dance has a little shameless behaviour in the past
Mac Specs: Soon to own

deer dance is offline
The 0xffff is Hexadecimal, a counting language

It converts to: 307866666666

Where is this coming from?


Proud Python Programmer/HTML Expert
Believer in Mac OS 7
QUOTE Thanks
njdevilfan26

 
Member Since: Jan 27, 2009
Posts: 8
njdevilfan26 is on a distinguished road

njdevilfan26 is offline
its just something from an objective c book i did not understand
QUOTE Thanks
daimos

 
Member Since: Jan 28, 2009
Posts: 5
daimos is on a distinguished road
Mac Specs: macbook 2.1ghz leopard

daimos is offline
C looks for main() not Main() to start executing. been a while, i might be wrong.
QUOTE Thanks
deer dance

 
deer dance's Avatar
 
Member Since: Jan 23, 2009
Location: Indiana
Posts: 162
deer dance has a little shameless behaviour in the past
Mac Specs: Soon to own

deer dance is offline
No, you're right.


Proud Python Programmer/HTML Expert
Believer in Mac OS 7
QUOTE Thanks
njdevilfan26

 
Member Since: Jan 27, 2009
Posts: 8
njdevilfan26 is on a distinguished road

njdevilfan26 is offline
ignore the syntax errors in the beginning of each line. What does the "0x" in front of 0xffff mean?
QUOTE Thanks
mystic_fm

 
Member Since: Mar 15, 2007
Posts: 161
mystic_fm will become famous soon enough
Mac Specs: 17" MacBook Pro, 2.33GHz C2D, 2GB RAM

mystic_fm is offline
The 0x prefix tells the compiler that the number value "ffff" is given in base 16 (hexadecimal) rather than base 10 (decimal). In hexadecimal, A through F are digits just like 0 through 9.

To understand this better, I recommend reading at least the first 1/3 or so of the Wikipedia page on hexadecimal.
QUOTE Thanks
njdevilfan26

 
Member Since: Jan 27, 2009
Posts: 8
njdevilfan26 is on a distinguished road

njdevilfan26 is offline
thanks
QUOTE Thanks

Post Reply New Thread Subscribe


« Help with XCode and Fortran | Simplest Instructions for Compiling »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
The QUESTION Game ToddG Schweb's Lounge 159 08-15-2007 05:25 PM
Boot-Up Question Mark Folder Impending Doom Question. bingwalker OS X - Operating System 3 07-10-2007 05:19 AM
Ask 'me' a question... eric Schweb's Lounge 22 01-12-2007 06:33 AM
Video production question macinsandiego Movies and Video 4 11-17-2004 07:39 AM
Postscript question battleangel444 OS X - Operating System 2 07-09-2004 12:45 PM

All times are GMT -4. The time now is 05:12 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?