This document discusses variables in C programming, including that a variable is a location in memory that can store data, variables have a name, datatype, size and value, and variables must follow identifier rules. It also summarizes the primary data types in C like int, char, float, and double, and how to declare single variables and multiple variables, initialize variables, assign values to variables from code or input, and print values to the output console using printf().
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
55 views
03 Variables in C Programming Language
This document discusses variables in C programming, including that a variable is a location in memory that can store data, variables have a name, datatype, size and value, and variables must follow identifier rules. It also summarizes the primary data types in C like int, char, float, and double, and how to declare single variables and multiple variables, initialize variables, assign values to variables from code or input, and print values to the output console using printf().
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6
Variables in C Programming
Language Datatype, Variable Declaration, Variable Definition Variable Concept
• Data container or Location of Main Memory where data can be stored
• Its value can be changed during execution.
• Each Variable has a name, datatype, size and value.
• Variable name is defined based on Identifier rules
• Variable Datatype can be set from the built-in data types
Primary Data Types • ANSI C supports different classes of data types Datatypes
• Primitive data types can be directly used to Primitive
Derived DT DT declare the variable • Integer – Keyword int used for integer data types int Arrays
• Character – Keyword char used for character data float Pointers
types char Structures • Floating Point – Keyword float used for single precision floating point numbers double
• Double Floating Point – Keyword double used for
double precision floating point numbers void Variable Syntax • Creating a Single Variable or multiple variables (Variable Declaration) • DATATYPE VARIABLE_NAME; • DATATYPE VARIABLE1, VARIABLE2, VARIABLE3, …; • int var; • int var1,var2,var3;
• Creating a variable and initializing a value to it(Variable Initialization)
• DATATYPE VARIABLE_NAME = VALUE; • int var1 = 100; Assigning Value to Variable We can assign value to already created variable in source code or via input console at runtime 1. Assigning value via source code variable_name = value; 2. Assigning value via input console can be achieved by scanf() function Data Type Format Specifier int %d float %f char %c string %s double %lf Printing Value of Variable to Output Console • Value of a variable can printed to output console by printf() function