#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    6
    Rep Power
    0

    Please explain this code


    #include<stdio.h>
    #define clrscr() 100
    main()
    {

    printf("%d",clrscr);
    }


    * how we can use clrscr but i tried the same replacing with printf that didn't worked ,
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,413
    Rep Power
    1871
    Perhaps focus on fixing the compilation errors to begin with.
    Code:
    $ gcc -Wall bar.c
    bar.c:3:1: warning: return type defaults to ‘int’ [-Wreturn-type]
    bar.c: In function ‘main’:
    bar.c:6:13: error: ‘clrscr’ undeclared (first use in this function)
    bar.c:6:13: note: each undeclared identifier is reported only once for each function it appears in
    bar.c:7:1: warning: control reaches end of non-void function [-Wreturn-type]
    $
    Now you could fix it by doing this (remove parentheses on the macro declaration)
    #define clrscr 100

    OR
    by doing this (add parentheses on the macro expansion)
    printf("%d",clrscr());

    But this will just result in the program printing "100" on screen.

    Neither of them will actually clear the screen, if that was your intention.

    clrscr() will only clear the screen if your platform supports the clear screen function. Just declaring "#define clrscr" doesn't magic into existence something to clear the screen for you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    6
    Rep Power
    0

    repl to Salem


    Hi, I got it,
    It have printed the result as 100 but
    is this same works with predefined library functions ....
  6. #4
  7. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,413
    Rep Power
    1871
    You can print the result of any function that returns an integer.
    Say
    Code:
    printf("Result=%d\n", printf("This is a very long message indeed\n") );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  8. #5
  9. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,117
    Rep Power
    1803
    Originally Posted by chaitanya.kk
    Hi, I got it,
    It have printed the result as 100 but
    is this same works with predefined library functions ....
    clrcsr() is not a function - it is a "function-like" macro. The C preprocessor simply replaced it with the literal constant 100.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    6
    Rep Power
    0
    Thank U

IMN logo majestic logo threadwatch logo seochat tools logo