Tags:
create new tag
, view all tags
Hello World in C, then some variations (experiments) as I learn, initially re conditional statements.

The book I'm working from (for the moment) is Red Hat Linux 6 Unleashed; David Pitts, Bill Ball, et. al.; Sams; 1st Printing, 1999; ISBN 0-672-31689-7.

For my own information, I have my test C programs stored under directory ~/test_C on system5 -- maybe someday I should upload them here.

See:

Contents

Hello World

In file hello.c:

main()
{
printf("Hello, World\n");
}

To compile and run:

#gcc hello.c # ./a.out

Testing the Leap Year Conditional Expression

Modified to test an expression intended to test for leap years:

main()
{
printf("Hello, World\n");
int year;
year=1960;
printf("%4d\n",(((year%4)==0)&&((year%100!=0))||((year%400)==0)));
}

Evaluating the Leap Year Conditional

Double check the parenthesis count -- copied and pasted without testing.

This does not consider whatever it's called -- "short circuit evaluation" (or even left to right, it just consists of "snapshots" of how I (a person) might think of the sequence of evaluation -- it's useful to recognize the generalities of what happens, but, AFAIK, most computers / compilers would evaluate the expression left to right, and, IIRC, C will do a short circuit evaluation which means once one side of the or evaluates to true (non zero), the other side of the or is not evaluated.

Remember that zero = false, non-zero = true in C. Do I need to remember that, or is that just "the truth" about Boolean algebra?

Assume year=1960:

(((year%4)==0)&&((year%100!=0))||((year%400)==0)))
(((1960%4)==0)&&((1960%100!=0))||((1960%400)==0)))
(((0)==0)&&((60!=0))||((360)==0)))
(((1)&&((1))||((0)))
(((1))||((0)))
1

<Currently, no significant content below this line.>

Contributors

  • () RandyKramer - 02 Apr 2003
  • <If you edit this page: add your name here; move this to the next line; and include your comment marker (initials), if you have created one, in parenthesis before your WikiName.>

Page Ratings

Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r4 - 2003-04-03 - RandyKramer
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by PerlCopyright 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding WikiLearn? WebBottomBar">Send feedback
See TWiki's New Look