LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-21-2012, 09:20 AM   #1
mscoder
LQ Newbie
 
Registered: Jun 2011
Posts: 18

Rep: Reputation: Disabled
the o/p of given code comes out as 4 which i cnt intrpret..pls help..


Code:
#include<stdio.h>
#define boo(x) x/4
main(){
int I;
I=64/boo(4);
printf("%d\n",I);
}
 
Old 07-21-2012, 09:47 AM   #2
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Hi.

You forgot parentheses in the macro:
Code:
$ cat test.c
#include<stdio.h>
#define boo(x) x/4
main(){
int I;
I=64/boo(4);
printf("%d\n",I);
}
$ cpp test.c
.....
main(){
int I;
I=64/4/4;
printf("%d\n",I);
}
Division is left associative: 64/4/4 = (64/4)/4 = 16/4 = 4. The correct macro would be
Code:
#define boo(x) (x/4)
which gives 64/(4/4) = 64/1 = 64.
 
2 members found this post helpful.
  


Reply

Tags
printf



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] return -1 of main but get exit code is 255? why? pls advise. youxi600 Linux - Newbie 13 06-30-2011 02:14 PM
cnt login mosh_rob Linux - Newbie 3 11-02-2009 10:08 AM
pls convert this windows code into linux code nagendrar Programming 6 06-03-2008 07:00 AM
pls pls pls help me ! i'm tired with httpd config on fedora apache 2.0.48 AngelOfTheDamn Fedora 0 01-24-2004 05:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration