Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 07:59

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Inadequate Knowledge of Preprocessor Directives

Discussion on Inadequate Knowledge of Preprocessor Directives within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Dec 2022
Posts: 14
Received Thanks: 0
Inadequate Knowledge of Preprocessor Directives

I'm working on a C program that uses preprocessor directives, and I'm having trouble understanding an issue with my code. Here's some of my code:
Code:
#include <stdio.h>

#define SQUARE(x) x * x

int main() {
    int result = SQUARE(2 + 3);
    printf("Result: %d\n", result);

    return 0;
}
This code was supposed to compute the square of the total of 2 + 3, which should be 25. However, the outcome was not what I had hoped for. I assume it is connected to how the preprocessor handles the macro, but I'm not certain, so I read this article but need more information about it. Could you kindly explain why I'm not receiving the desired results and offer a method to correct it?
TonyFinch09 is offline  
Old 10/15/2023, 10:19   #2

 
nÂsty.'s Avatar
 
elite*gold: 30
The Black Market: 158/0/0
Join Date: Feb 2013
Posts: 1,469
Received Thanks: 783
2 + 3 * 2 + 3 ? = 2+ 5+ 3 = 11

#define SQUARE(x) ((x) * (x)) test this

Quote:
#include <stdio.h>

#define SQUARE(x) ((x) * (x))

int main() {
int result = SQUARE(2 + 3);
printf("Result: %d\n", result);

return 0;
}
use ChatGPT for this art of questions, it helps.
I use it when i analyse my code, is a nice helper tool.

PS: dont forget the math laws.

and "#define" only change the macro text, not more, be careful
nÂsty. is offline  
Reply


Similar Threads Similar Threads
Preprocessor directives Help!
03/21/2015 - C/C++ - 3 Replies
Hi guys i'm trying to code a handle to a file so that i can write to it, i'm a bit confused cause i don't know if i can make it work that way. First i tried this way: #include <stdio.h> #define FILENAME "C:\\data.dat" #define EXIST (fopen(FILENAME,"r") == NULL)?1:0 //Exist or not #if EXIST > 0
Request of: Knowledge / AutoDropper
11/23/2007 - Conquer Online 2 - 2 Replies
Can anyone help me make an autodropper for mining? Similar to automining but it will drop all the ores it can with a push of a button? Such as pressing the button, and macro/(auto here) will start and make all items in the inventory drop? I have seen the Trading Super Fast macro thingie, it seems like it CAN work in the same way but the part when it presses down to scroll the trade window makes the miner move so if anyone can also let me know how to remove that one click scrolling down ,...
put your knowledge or gm code here
07/17/2007 - Conquer Online 2 - 0 Replies
Is there any possible way to get the code gm`s use if so im sure EVERYONE would like it if not just close this
Anyone with pretty GOOD knowledge of AutoIt look!
03/04/2006 - Conquer Online 2 - 2 Replies
1.Ok as obvious, im an AutoIt programmer. As you guys know i did say that i was making a tao bot, but i thought i knew more about coding than i did, and i couldnt do the advnaced stuff. Anyways, to the point... I need 1 person that knows quite a bit about AutoIt coding. Together we shall make my idea come to life, the idea will include about everything that is macro related. Message me PLEASE if you are interested!!!! 2.Second of all, i know it might be possible to add ADVANCED+++ coding...



All times are GMT +1. The time now is 07:59.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.