L2 - 2. C FUNDAMENTALS Example: Printing a Message /*...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
2. C FUNDAMENTALS
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include <stdio.h> int main(void) { printf("To C, or not to C: "); printf("that is the question.\n"); return 0; }
Background image of page 2
Comments • Begin with /* and end with */. /* This is a comment */ • May extend over more than one line. /* This comment starts on one line, but ends on another. */ • Warning: Failing to close a comment will cause the compiler to ignore part of your program. printf("Hello"); /* forgot to close this comment. .. printf("Goodbye"); /* so it ends here */ • In C99, comments can also be written this way: // This is a comment. This type of comment is terminated by the end of the line.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Example: Computing the Volume /* Illustrates the use of variables, expressions, and assignment statements */ #include <stdio.h> int main(void) { int height, length, width, volume; height = 5; length = 20; width = 10; volume = height * length * width; printf("The height is %d\n", height); printf("The length is %d\n", length); printf("The width is %d\n", width); printf("The volume is %d\n", volume); return 0; }
Background image of page 4
Variables A variable is a memory location with a name Each variable used in a program has to be declared
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Declarations Remember <function_definition>::= <function_header><function_body> <function_body>::=<compound_statement> <compound_statement>::= { [declarations][<statements>] }
Background image of page 6
Declarations <declarations>::=<declaration>[<declarations>] <declaration>::= <data_type><variable_names> ; <variable_names>::=<variable_name>[ , <variable_names>] <data_type>::= int | float |… <variable_name>::=<identifier> <identifier>::=<alphas>[<alphanums>] <alphas>::=<alpha>[<alphas>] <alpha>::=_|A|B|…|z <alphanums>=<alphanum>[<alphanums>] <alphanum>=<alpha>|<digit>
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Variables Each variable has A name (identifier) A memory location (address) A data type A value The interpretation (information) of the data stored at that memory location Depends on the data type
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/08/2011 for the course CGS 3460 taught by Professor Staff during the Summer '08 term at University of Florida.

Page1 / 30

L2 - 2. C FUNDAMENTALS Example: Printing a Message /*...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online