cs31 lecture 17

7 float examples float f 0 ok float f 00 ok float

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: e extra cautious: analyze the input to ensure the range of Be variables! variables! 7 float: examples float f = 0; // ok float f = 0.0; // ok float f = 0.0f; // ok float f = -0; // ok float f = 42; // ok float f = 12312434123.0f; // ok double f = -42; // ok double 8 char x An arbitrary character, from the ASCII table x Standard ASCII: 128 characters x Extended ASCII: 256 characters x Range: [-128,127] x Possible qualifier: unsigned x Use single quote to set a value using a character Examples: char x = ‘a’; char char x = 97; char 9 A program in C++ x A program is made of functions x There must be a main function, which is called when the There program starts program x This function has a specific name and prototype int main()
 { some code goes here… some } 10 Syntax of a function <return type> <name> ([arguments])
 { } x<return type> is the type of the data returned by the <return function function Examples: int, float, void x<name> is the name of the function 11 A typical simple main function int main()
 { /// list of instructions: / return 0; return } xThe function returns 0, indicating it terminated without an The error error xWe use // to mark the start of a comment line 12 Rules for variable naming x A variable is referred to by its name used in the declaration variable statement, and is case-sensitive statement, Example: int main()
 { int foo; int foo = 42; foo } x Restrictions on the name: Starts by a letter, or _ Can...
View Full Document

Ask a homework question - tutors are online