Constant in C



  • Why does the code work like that (when the constant is declared as a line):

    #include <stdio.h>
    #include <stdlib.h>
    #define A "3"
    

    int main(void){
    puts(A);
    }

    (number)

    #include <stdio.h>
    #include <stdlib.h>
    #define A 3

    int main(void){
    puts(A);
    }

    What needs to be fixed?



  • http://www.opennet.ru/man.shtml?topic=puts&category=3&russian=0 Tells us the prototype's in. puts() such as:

    int puts(const char *s);
    

    I mean, as an argument, this function is taken by the index to charNot the number. If there's a number to be removed, or http://www.opennet.ru/man.shtml?topic=printf&category=3 Analogs:

    printf( "%d\n", A );
    

    Or transfer the number to the line, then remove it (see man sprintf).


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2