Variables and constants, Input/output operations,
MINAKSHI SHARMA
Variables
Definition:�A variable is a storage location in memory with a specific name and type that holds data which can change during program execution.
data_type variable_name;
int age;
float salary;
Variables Contd.
Rules for Naming Variables:
Usage:
Constants
Constants Contd.
Defining Constants:
#define PI 3.14159
const int MAX_AGE = 100;
Rules for Constants:
Usage:�Constants are used for fixed values in a program to improve readability and maintainability.
Difference Between Variable and Constant
Input Operations
Standard Input: scanf()
The scanf() function is used to take input from the user during the execution of the program.
Syntax:
scanf("format_specifier", &variable);
Explanation:-
Input Operations Example
#include <stdio.h>
int main()
{
int age;
printf("Enter your age: ");
scanf("%d", &age); // Takes integer input printf("Your age is: %d\n", age);
}
Output Operations
Standard Output: printf()
The printf() function is used to display output on the screen.
Syntax:
printf(“msg”);
printf("format_specifier", value);
Input & Output Operations Example
#include <stdio.h>
int main()
{
int age;
printf("Enter your age: ");
scanf("%d", &age); // Takes integer input printf("Your age is: %d\n", age);
}
format_specifier
format_specifier determines how the value will be displayed.
Thanks