We relaunched the TWiki.org project with an expanded TWiki charter, and we invite you to participate! The TWiki.org Code of Conduct agreement took effect on 27 Oct 2008. We ask existing twiki.org users to opt-in. You need to opt-in to participate in the Blog, Codev, Plugins and TWiki webs. -- PeterThoeny - 27 Oct 2008
You are here: TWiki> Wikilearn Web>CplHelloWorld (03 Apr 2003, RandyKramer)
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

Topic revision: r4 - 03 Apr 2003 - 14:12:00 - RandyKramer
Wikilearn.CplHelloWorld moved from Wikilearn.CHelloWorld on 03 Apr 2003 - 14:11 by RandyKramer - put it back
 
TWIKI.NET
Copyright © 1999-2008 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback
See TWiki's New Look