Write Programs to learn data type, variables, If-else statement.
Variables : Variables are nothing but a name of the memory location. It is used to store data. Its value can be changed, and it can be reused many times.It is a way to represent memory location through symbol so that it can be easily identified .
Example :
Data type : data types are declarations for variables. This determines the type and size of data associated with variables. data types are of three types :
- Primitive data type
- User defined data type
- Derived data type
Data Types are used to:
- Identify the type of a variable when it declared.
- Identify the type of the return value of a function.
- Identify the type of a parameter expected by a function.
Primitive data type :
Data types | Description |
---|
void | As the name suggests, it holds no value and is generally used for specifying the type of function or what it returns. If the function has a void type, it means that the function will not return any value. |
int | Used to denote an integer type. |
char | Used to denote a character type. |
float, double | Used to denote a floating point type. |
int *, float *, char * | Used to denote a pointer type. |
Derived data type :
Data Types | Description |
---|
Arrays | Arrays are sequences of data items having homogeneous values. They have adjacent memory locations to store values. |
References | Function pointers allow referencing functions with a particular signature. |
Pointers | These are powerful C features which are used to access the memory and deal with their addresses. |
User Defined data types :
Data Types | Description |
---|
Structure | It is a package of variables of different types under a single name. This is done to handle data efficiently. "struct" keyword is used to define a structure. |
Union | These allow storing various data types in the same memory location. Programmers can define a union with different members, but only a single member can contain a value at a given time. It is used for |
Enum | Enumeration is a special data type that consists of integral constants, and each of them is assigned with a specific name. "enum" keyword is used to define the enumerated data type . |
Program :
#include<stdio.h> #include<conio.h> void main() { int a = 4; // positive integer data type float b = 5.2324; // float data type char c = 'Z'; // char data type long d = 41657; // long positive integer data type short g = 130; // short +ve integer data type double i = 4.1234567890; // double float data type printf("%d",a); printf("\n%f",b); printf("\n%c",c); printf("\n%li",d); printf("\n%hi",g); printf("\n%lf",i); } |
---|
Output :
4
5.232400
Z
41657
130
4.123457
If-else statement :
If the test expression is evaluated to true,
- statements inside the body of if are executed.
- statements inside the body of else are skipped from execution.
If the test expression is evaluated to false,
- statements inside the body of else are executed
- statements inside the body of if are skipped from execution

Syntax :
if (condition) { // execute if the test expression is true } else { // execute if the test expression is false } |
---|
Example :
#include<stdio.h> #include<conio.h> void main() { int i; printf("Enter value : "); scanf("%d", &i); if (i%2 == 0) { printf("%d is even .",i); } else { printf("%d is odd .",i); } } |
---|
Output :
Enter value : 5
5 is odd .
For more RTU/BTU II Sem Computer Programming Lab Experiments CLICK HERE