The document discusses variables and constants in C programming. It explains that C programs typically include variable declarations and constants. Variables store values in memory locations and must be declared with a name and data type. The document outlines the rules for naming variables in C and explains how to declare and define variables. It also discusses using format specifiers to work with different data types and how to take user input and print output using variables.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
44 views
Lecture 04 C Variables and Constants
The document discusses variables and constants in C programming. It explains that C programs typically include variable declarations and constants. Variables store values in memory locations and must be declared with a name and data type. The document outlines the rules for naming variables in C and explains how to declare and define variables. It also discusses using format specifiers to work with different data types and how to take user input and print output using variables.
C program structure • Virtually all structured programs, including C programming share a similar overall structure: • Statements to establish the start of the program e.g. #include directives. • Variable declarations and constants • Program control statements (blocks of code) e.g. Conditional statements (if, if… else, etc.), loops (for loop, while loop, etc.)
Statements to establish the start of the C program • The #include directives or preprocessor headers are used to start C. • The next to the directives is the main function, named main(). • From here is where open curly bracket ({) shows the beginning of our program.
Variables • A variable is a location in memory where a value can be stored for use by a program. • Example: • int integer1; • int integer2; • int sum; • These definitions specify that the variables integer1, integer2 and sum are of type int.
Variable names • All variable definitions must include two things variable name and its data type. • To indicate the memory location, each variable should be given a unique name called identifier. • To declare any variable in C language you need to follow rules of C language.
Format specifiers cont… Supported data Format specifier Description types char %c Character unsigned char short unsigned short %d Signed integer int long %f Floating point float %lf Floating point double %s String char *
2-Introduction to Structured Programming - C language History and Introduction - Datatypes-Basic IO statements - Variables - Keywords - Expression evaluation using operator precedence-17-12-2024