What is the output of following code?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vensriram
    New Member
    • Aug 2010
    • 48

    #1

    What is the output of following code?

    #define EXMP 25
    main ( )
    { int exmp = 35;
    printf (“\nvalue of exmp is %d”,EXMP);
    }

    my answer is 35
    Is it correct?
  • Oralloy
    Recognized Expert Contributor
    • Jun 2010
    • 988

    #2
    Why do you think 35 is the correct answer?

    Comment

    • vensriram
      New Member
      • Aug 2010
      • 48

      #3
      In C the IDENTIFIERS are case sensitive. Hence I think the same applies here? Is it ok

      Comment

      • Oralloy
        Recognized Expert Contributor
        • Jun 2010
        • 988

        #4
        Not only are identifiers case sensitive, but keywords are as well.

        In this case, you also have a macro, which modifies the source code before the compiler even gets ahold of it. Your code after preprocessing is equivalent to:
        Code:
        main ( )
        { int exmp = 35;
        printf (“\nvalue of exmp is %d”,25);
        }
        Observe that the definition is erased and the token EXMP is replaced with the value from the definition.

        Hopefully that helps a little.

        Cheers!
        Last edited by Oralloy; Aug 10 '10, 06:43 PM. Reason: insert blank at head of code block

        Comment

        • vensriram
          New Member
          • Aug 2010
          • 48

          #5
          yes u r correct

          Thanks Oralloy...

          Comment

          • Oralloy
            Recognized Expert Contributor
            • Jun 2010
            • 988

            #6
            You're welcome, vensriram.

            Cheers!

            Comment

            Working...