The Gateway to Computer Science Excellence
0 votes
96 views

Please explain the solution, whats the actual logic in questions of Preprocessor codes?

in Programming by Junior (675 points)
recategorized by | 96 views
+1
Just Run this two code.

#include <stdio.h>
#define fo(a) a*a

int main()
{
    //printf("Hello World");
    int a = 3;
    
    printf("%d", foo(a +1));

    return 0;
}



2.
#include <stdio.h>
int foo(int a)
{
    return a * a;
}

int main()
{
    //printf("Hello World");
    int a = 3;
    
    printf("%d", foo(a +1));

    return 0;
}

 

+1
+1
While compilation itself , black(a) , black(a+1) and white(a) would be replaced with

a+a*a*a+1+a+1*a+1 - a - a*a

Now a is replaced with 3 ,

3 + 3 * 3 * 3 + 1 + 3 + 1 * 3 + 1 - 3 - 3 * 3 , And then execution based on precedence and associativity is done.
+1
Yes Program should eliminate braces during compilation. In that case precedence would get changed.
0
here - is before white ,it will not change whole expression of white ?

pls reply

Please log in or register to answer this question.

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,321 answers
198,399 comments
105,152 users