Jenkins
CI/CD Pipeline: Learn with Example
What is a CI/CD pipeline? A CI/CD pipeline automates the process of software delivery. It builds code,...
A variable is an identifier which is used to store some value. Constants can never change at the time of execution. Variables can change during the execution of a program and update the value stored inside it.
A single variable can be used at multiple locations in a program. A variable name must be meaningful. It should represent the purpose of the variable.
Example: Height, age, are the meaningful variables that represent the purpose it is being used for. Height variable can be used to store a height value. Age variable can be used to store the age of a person
A variable must be declared first before it is used somewhere inside the program. A variable name is formed using characters, digits and an underscore.
Following are the rules that must be followed while creating a variable:
Following are the examples of valid variable names in a 'C' program:
height or HEIGHT _height _height1 My_name
Following are the examples of invalid variable names in a 'C' program:
1height Hei$ght My name
For example, we declare an integer variable my_variable and assign it the value 48:
int my_variable; my_variable = 48;
By the way, we can both declare and initialize (assign an initial value) a variable in a single statement:
int my_variable = 48;
'C' provides various data types to make it easy for a programmer to select a suitable data type as per the requirements of an application. Following are the three data types:
There are five primary fundamental data types,
Array, functions, pointers, structures are derived data types. 'C' language provides more extended versions of the above mentioned primary data types. Each data type differs from one another in size and range. Following table displays the size and range of each data type.
Data type | Size in bytes | Range |
Char or signed char | 1 | -128 to 127 |
Unsigned char | 1 | 0 to 255 |
int or signed int | 2 | -32768 to 32767 |
Unsigned int | 2 | 0 to 65535 |
Short int or Unsigned short int | 2 | 0 to 255 |
Signed short int | 2 | -128 to 127 |
Long int or Signed long int | 4 | -2147483648 to 2147483647 |
Unsigned long int | 4 | 0 to 4294967295 |
float | 4 | 3.4E-38 to 3.4E+38 |
double | 8 | 1.7E-308 to 1.7E+308 |
Long double | 10 | 3.4E-4932 to 1.1E+4932 |
Note: In C, there is no Boolean data type.
Integer is nothing but a whole number. The range for an integer data type varies from machine to machine. The standard range for an integer data type is -32768 to 32767.
An integer typically is of 2 bytes which means it consumes a total of 16 bits in memory. A single integer value takes 2 bytes of memory. An integer data type is further divided into other data types such as short int, int, and long int.
Each data type differs in range even though it belongs to the integer data type family. The size may not change for each data type of integer family.
The short int is mostly used for storing small numbers, int is used for storing averagely sized integer values, and long int is used for storing large integer values.
Whenever we want to use an integer data type, we have place int before the identifier such as,
int age;
Here, age is a variable of an integer data type which can be used to store integer values.
Like integers, in 'C' program we can also make use of floating point data types. The 'float' keyword is used to represent the floating point data type. It can hold a floating point value which means a number is having a fraction and a decimal part. A floating point value is a real number that contains a decimal point. Integer data type doesn't store the decimal part hence we can use floats to store decimal part of a value.
Generally, a float can hold up to 6 precision values. If the float is not sufficient, then we can make use of other data types that can hold large floating point values. The data type double and long double are used to store real numbers with precision up to 14 and 80 bits respectively.
While using a floating point number a keyword float/double/long double must be placed before an identifier. The valid examples are,
float division; double BankBalance;
Character data types are used to store a single character value enclosed in single quotes.
A character data type takes up-to 1 byte of memory space.
Example,
Char letter;
A void data type doesn't contain or return any value. It is mostly used for defining functions in 'C'.
Example,
void displayData()
Type declaration of a variable
int main() { int x, y; float salary = 13.48; char letter = 'K'; x = 25; y = 34; int z = x+y; printf("%d \n", z); printf("%f \n", salary); printf("%c \n", letter); return 0;}
Output:
59 13.480000 K
We can declare multiple variables with the same data type on a single line by separating them with a comma. Also, notice the use of format specifiers in printf output function float (%f) and char (%c) and int (%d).
Constants are the fixed values that never change during the execution of a program. Following are the various types of constants:
An integer constant is nothing but a value consisting of digits or numbers. These values never change during the execution of a program. Integer constants can be octal, decimal and hexadecimal.
Example, 111, 1234
Above are the valid decimal constants.
Example, 012, 065
Above are the valid decimal constants.
Example, 0X2, 0Xbcd
Above are the valid hexadecimal constants.
The octal and hexadecimal integer constants are very rarely used in programming with 'C'.
A character constant contains only a single character enclosed within a single quote (''). We can also represent character constant by providing ASCII value of it.
Example, 'A', '9'
Above are the examples of valid character constants.
A string constant contains a sequence of characters enclosed within double quotes ("").
Example, "Hello", "Programming"
These are the examples of valid string constants.
Like integer constants that always contains an integer value. 'C' also provides real constants that contain a decimal point or a fraction value. The real constants are also called as floating point constants. The real constant contains a decimal point and a fractional value.
Example, 202.15, 300.00
These are the valid real constants in 'C'.
A real constant can also be written as,
Mantissa e Exponent
For example, to declare a value that does not change like the classic circle constant PI, there are two ways to declare this constant
#include <stdio.h> int main() { const double PI = 3.14; printf("%f", PI); //PI++; // This will generate an error as constants cannot be changed return 0;}
#include <stdio.h> #define PI 3.14 int main() { printf("%f", PI); return 0;}
What is a CI/CD pipeline? A CI/CD pipeline automates the process of software delivery. It builds code,...
YouTube to MP3 Converters are applications that enable you to save YouTube video clips in mp3...
Computer Programming is a step-by-step process of designing and developing various computer...
What is Statistical Inference? Stastitical inference is the art of generating conclusions about...
A download manager is a software that helps you to prioritize your downloads, faster download...
Training Summary BigData is the latest buzzword in the IT Industry. Apache’s Hadoop is a leading Big...