clanguage
clanguage
#include <stdio.h>
int main() {
int n1, n2, sum;
printf("Enter two integers: ");
scanf("%d %d", &n1, &n2);
sum = n1 + n2; // calculate the sum
printf("%d + %d = %d", n1, n2, sum);
return 0;
}
These keywords are standardized by the C language specifications, and they must be
written in lowercase letters. It's important to note that C is case-sensitive, so auto is
different from Auto or AUTO.
Constants
A constant is a value that remains unchanged during the execution of a program.
Constants can be of various types and they are used to represent fixed values that do
not change during the program's execution. Constants are typically used in programs
to assign names to values that are not expected to change.
Numeric Constants:
Integer Constant: These are whole numbers without a fractional component.
For example: const int myInteger = 42;
Here, myInteger is a constant of type int with a value of 42.
Floating-Point Constants: These are numbers with a fractional component. For
example:
const float myFloat = 3.14;
Here, myFloat is a constant of type float with a value of 3.14.
Character Constant: Character constants are enclosed in single quotes. For example:
const char myChar = 'A';
Here, myChar is a constant of type char with a value of 'A'.
Constants can be defined using the const keyword, which indicates that the value
assigned to the variable should not be changed during the program's execution. The
use of ‘const’ also helps in making the code more readable and self-explanatory, as it
explicitly conveys the intention that the value should not be modified.
Data Types in C
Data types are the type of data stored in a C program. The compiler needs to
understand the type of predefined data it will encounter in the program. A data type
is an attribute that tells a computer how to interpret the value.
C provides several built-in data types, such as integer (int), character (char), floating-
point (float), and double-precision floating-point (double), among others. Each data
type has its own set of possible values and operations that can be performed on it.
2. Character (char): Refers to all the character sets within single quotes such as ‘a’, ‘A’,
etc.
Example:
#include <stdio.h>
void main() {
char c = 'b';
printf("The character value is: %c
\n", c);
}
3. Floating-point (float): Refers to all the real number values or decimal points, such
as 3.14, 10.09, 5.34, etc.
Example:
#include <stdio.h>
void main() {
float f = 7.2357;
printf("The float value is: %f \n", f);
}
4. Double (double): Used when the range exceeds the numeric values that do not
come under either floating-point or integer data type.
Example:
#include <stdio.h>
void main()
{
double d = 71.2357455;
printf("The double value is: %lf \n", d);
}
Data Type Modifiers In C: Modifiers are C keywords that modify the meaning of
fundamental data types. C Programming Language has four data type modifiers:
long
short
signed
Unsigned
Array
An array in C is a collection of multiple values of a similar data type and is stored in
a contiguous memory location. An array can consist of chars, integers, doubles, etc.
Structure
It is a data type that can store variables of similar or different data types. For example,
we can use structures to store information about an employee, such as the employee’s
name, employee ID, salary, and more. The ‘struct’ keyword defines a structure.
Union
A union is a group of elements with similar or different data types. In a union, the
memory location is the same for all the elements. Its size will be equal to the memory
required for the largest data type defined. We use the keyword ‘union’ to define a
union.
Void
The void is just an empty data type that depicts that no value is available. Typically,
the void is used for functions. When we declare a function as void, it doesn’t have to
return anything.
void sum (int a, int b);