Like Tree2Likes
  • 2 Post By laserlight

Simple lines of code

This is a discussion on Simple lines of code within the C Programming forums, part of the General Programming Boards category; Hello. If anyone could explain to me in depth these short lines of code, so that I can understand other ...

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    1

    Simple lines of code

    Hello.

    If anyone could explain to me in depth these short lines of code, so that I can understand other ones similar to this one when they show up. I know the rest, I just need the bit in the printf brackets explained. Thanks.

    Code:
    #define NUL '\0'
    void main(){
    char c=NULL
    printf("%d",(!c) ? x : c);}

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,632
    I'll let my compiler do the explaining:
    Code:
    test.c:2:6: warning: return type of 'main' is not 'int' [-Wmain]
    test.c: In function 'main':
    test.c:3:8: error: 'NULL' undeclared (first use in this function)
    test.c:3:8: note: each undeclared identifier is reported only once for each function it appears in
    test.c:4:1: error: expected ',' or ';' before 'printf'
    test.c:3:6: warning: unused variable 'c' [-Wunused-variable]
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,831
    You want (!c) ? x : c explained.
    That's conditional expression. The part in the parenthesis is evaluated as to TRUE or FALSE. If it's TRUE then the first statement after '?' is executed. If FALSE then the statement after ':'.
    If c was zero then !c is TRUE so therefore 'x' is executed (stacked, printed).
    If c was non-zero then !c if FALSE so therefore 'c' is executed (stacked, printed).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Meaning of Code Lines
    By shwetha_siddu in forum C Programming
    Replies: 4
    Last Post: 10-14-2008, 04:54 PM
  2. Simple answer for intersecting lines?
    By LLINE in forum C++ Programming
    Replies: 6
    Last Post: 06-01-2008, 02:10 AM
  3. Checking lines of code
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 04-10-2008, 02:05 AM
  4. Lines of code per day.
    By abachler in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 10-26-2007, 09:20 AM
  5. What do these tow lines of code mean?
    By Gamma in forum C++ Programming
    Replies: 1
    Last Post: 04-25-2002, 04:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21