Chapter-2(Basic Fundamental tool)
1. Character Sets:
A character set is a set of characters with a specific encoding scheme used for representing textual information in a programming language. In C, the basic character set includes letters, digits, and special characters.
Example:-
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char myChar='A';
printf("Character: %c\n", myChar);
getch();
}
2. Keywords:
Keywords are reserved words in a programming language that have a predefined meaning. These words cannot be used as identifiers (names for variables, functions, etc.) because they are already used by the language.
Example:-
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int num = 5;
if(num > 0) {
printf("The number is positive.\n");
}
getch();
}
In this example, 'if'
is
keywords. instead of this example while, for, break, goto, else also are keywords.
3. Data Types:
A variable's data type defines the kind of data it can store. C supports various data types, including int, float, char, double, etc.
Example:-
#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
int integerVar = 10;
float floatVar = 3.14;
char charVar = 'A';
printf("Integer: %d\n", integerVar);
printf("Float: %f\n", floatVar);
printf("Character: %c\n", charVar);
getch();
}
4. Constants:
Constants are values that do not change while a program is running. They come in a variety of forms, including integer constants, floating-point constants, and character constants.
Example:-
#include <stdio.h>
#include<conio.h>
#define PI 3.14159 // Macro for a constant
void main()
{
clrscr();
const int MAX_VALUE = 100; // Constant variable
printf("PI: %f\n", PI);
printf("Max Value: %d\n", MAX_VALUE);
getch();
}
5. Variables:
Variables are containers for storing data values. Before they can be utilized, they need to be specified with a data type.
Example:-
#include <stdio.h>
#include<conio.h>
void main()
{
clrscr();
int age; // Declaration
age = 25; // Initialization
printf("Age: %d\n", age);
getch();
}
In this example, age is a variable of type int.
These fundamental concepts are the building blocks of C programming, and understanding them is crucial for writing effective and readable code.