{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture_1a_vars_data_types_formatted_IO (2)

lecture_1a_vars_data_types_formatted_IO (2) - Beginning...

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

View Full Document Right Arrow Icon
1 Beginning Concepts for Problem Solving in C: variables, data types, operators, and formatted IO BJ Furman 30JAN2010
Background image of page 1

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

View Full Document Right Arrow Icon
2 The Plan for Today The concept of data Constants vs. variables Variables naming rules data types Operators and their precedence Practice writing and executing C programs in ChIDE
Background image of page 2
3 Learning Objectives Following completion of today’s lab, you should be able to: List and explain the basic kinds of data Distinguish between variables and constants Declare integer, floating point, and character variables List the basic data types used in C Identify and explain commonly used operators in C Use C operators correctly according to their placement in the hierarchy chart Write and execute simple C programs in ChIDE Set up and evaluate expressions and equations using variables, constants, operators, and hierarchy of operations
Background image of page 3

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

View Full Document Right Arrow Icon
4 What and Why? Data => pieces of information we deal with in the problem solving process Why is it important to know about data types? Need to know about data types to effectively use a programming language It’s all just bits the lowest level! What would you rather work with… int i; float r; i = 3; r = cos(2*i*PI); or… 00000010 10000000 00000000 00000110 10000010 10000000 01111111 11111100 11001010 00000001 00000000 00000000 etc.
Background image of page 4
5 Kinds of Data (simplified view) The basic kinds of data that we will mostly use: Numeric Integers: Real (floating point) numbers: Character (are enclosed by single quotes in C) All letters, numbers, and special symbols Ex. ‘A’, ‘+’, ‘5’ String (are enclosed by double quotes in C) Are combinations of more than one character Ex. “programming”, “ME 30” Logical (also called ‘ Boolean ’ named after George Boole an English mathematician from the early 1800’s) True or False (1 or 0)
Background image of page 5

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

View Full Document Right Arrow Icon
6 Kinds of Data - Practice Data Type 1. 17 2. “George” 3. 2.35 4. 0.0023 5. -25 6. ‘m’ 7. 4.32E-6 8. “185.3” 9. 0 10. 1 If kind is ‘numeric’, then is it an integer or a floating point number?
Background image of page 6
7 Constants and Variables Constant A data element that never changes in your program 5, 62.37, 4.219E-6, “record_string”, ‘$’ i = j + 7; /* which one is the constant? */ first_letter = ‘a’; /* which one is the constant? */ Variable A data element that can take on different values Its name represents a location (address) in memory i = j + 7; /* which are variables? */ second_letter = ‘b’; /* which is the variable? */ Values are ‘assigned’ using a single equal sign ( = ) Read the statement: i = j + 7; NOTE!! Variables in C must be ‘ declared ’ before they can be used!
Background image of page 7

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

View Full Document Right Arrow Icon
8 Declaring Variables and Data Types Variables must be declared before they can be used Gives info to the compiler about: How many bytes of memory to set aside How to interpret the bytes (data) Example: int my_var; /* an integer variable my_var */ float sensor1; /* a float variable sensor1 */ char Letter01_a; /* a char variable Letter01_a */ Two parts are needed in the declaration: Data type designator (e.g., int ), (note, a ‘reserved word’) Identifier (i.e., a name: my_var ), must be a valid identifier
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.

{[ snackBarMessage ]}