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

    Join Date
    Aug 2012
    Posts
    4
    Rep Power
    0

    Separating if and else blocks in C


    So I'm trying to understand how C manages to decide which code is part of which block?

    For instance, here is a part of my code:
    Code:
    	if (circle[i].radius<0)
    	     circle[i].area = 0;
            else
    	     circle[i].area = process(circle[i].radius);
          printf("\nIdentifier: ");
          scanf("%s",circle[++i].text);
    Will the printf and scanf be a part of the else-block? Or will they be considered separate from the else-blok due to the indent? If the answer is yes, then how can I make it so that they are distinct from the else-block? Do I use braces?

    Does indentation matter at all in C? If you use braces consistently, then will indentation matter in the context of recognizing if and else blocks?

    What about for while and for loops?

    Thanks and appreciate all help !!!

    EDIT: Sorry, I just realized this was a Pythno forum. Could a moderator please move it to the C forum?

    BiP
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    White space in c source delimits tokens, and that's all.
    Guess the effect of this program then try it.
    Code:
    #include <stdio.h>
    main(t,_,a)char *a;{return!0<t?t<3?main(-79,-13,a+main(-87,1-_,
    main(-86,0,a+1)+a)):1,t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t==2?_<13?
    main(2,_+1,"%s %d %d\n"):9:16:t<0?t<-72?main(_,t,
    "@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l,+,/n{n+,/+#n+,/#\
    ;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l \
    q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# \
    ){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' \
    iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c \
    ;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')# \
    }'+}##(!!/")
    :t<-50?_==*a?putchar(31[a]):main(-65,_,a+1):main((*a=='/')+t,_,a+1)
      :0<t?main(2,2,"%s"):*a=='/'||main(0,main(-61,*a,
    "!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry"),a+1);}
    (I didn't test it.)

    Consider the differences between
    --x versus - -x
    or
    x&&y versus x& &y

    And perhaps you who learned the c trigraphs can think of other hideous examples.

    The c preprocessor requires that # start in column 1.
    Last edited by b49P23TIvg; August 6th, 2012 at 08:57 PM.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo