Machine-translated by Google. Questions are authored in English.
Top

Discussion

Point out the error in the program

#include <stdio.h>
#define SI(p, n, r) float si; si=p*n*r/100;
int main()
{
    float p=2500, r=3.5;
    int n=3;
    SI(p, n, r);
    SI(1500, 2, 2.5);
    return 0;
}

 

  • A.26250.00 7500.00
  • B.Nothing will print
  • C.Error: Multiple declaration of si
  • D.Garbage values

Answer: C

Correct answer: Error: Multiple declaration of si

The macro body declares si, so using it twice in the same block expands to two float si; declarations of the same name in the same scope - which the compiler rejects. This is the standard argument for wrapping a multi-statement macro in do { … } while(0), which gives each expansion its own block and its own scope.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.