Introduction to c programming :
An identifier, on the other hand, is a name given to a variable, function, or any other user-defined item. Identifiers are used to identify these items in the program and must follow certain rules. In C, an identifier must start with a letter or underscore and can contain letters, digits, and underscores. They are case sensitive, which means that "counter" and "Counter" are considered as different identifiers.
It's worth noting that C99 standard also introduced a new set of keywords such as "_Bool", "_Complex" and "_Imaginary"
Data Types in C language
The C programming language, data types refer to the type of data that a variable can hold. The standard data types in C include:
int: used to store integers (whole numbers)float: used to store floating-point numbers (numbers with decimal points)double: used to store double-precision floating-point numbers (larger and more precise than floats)char: used to store characters (letters, digits, and special characters)void: used to represent the absence of a value or a type_Bool: introduced in C99, used to store Boolean values (true or false)_Complex and _Imaginary : introduced in C99, used to store complex and imaginary numbers respectively.
In addition to these standard data types, C also allows the creation of user-defined data types using the typedef keyword or struct, union, and enum. It's also worth noting that C99 standard introduced "long long" and "long double" to represent the larger size of int and double respectively.
Constant and Variable Decleration in C : In C, constants and variables are declared using the keyword "const" and without keyword respectively.
A constant is a value that cannot be changed during the execution of the program. Constants are declared using the keyword "const" followed by the data type and the name of the constant. The value of a constant must be assigned at the time of declaration and cannot be changed later on.
For example:
const int MAX_LIMIT = 100;
const float PI = 3.14;
A variable, on the other hand, is a value that can be changed during the execution of the program. Variables are declared by specifying the data type followed by the name of the variable. The value of a variable can be changed later on.
For example:
int age;
float salary;
It is also possible to initialize a variable when it is declared, by assigning a value to it at the time of declaration.
int age = 25;
float salary = 50000;
It is considered a good practice to initialize the variable at the time of declaration
Format input and output in C In C, formatted input and output functions are used to read and write data from and to a stream, respectively, in a specific format. The two most commonly used formatted input/output functions are printf() and scanf().
- printf(): This function is used to print data to the standard output stream (typically the console). It takes a format string and a list of arguments, and prints them to the output stream according to the specified format. For example:
printf("Hello, World!\n");
int age = 25;
printf("My age is %d\n", age);
- scanf(): This function is used to read data from the standard input stream (typically the keyboard). It takes a format string and a list of addresses of variables, and reads data from the input stream according to the specified format. For example:
int age;
printf("Enter your age: ");
scanf("%d", &age);
Additionally, C also have other formatted input/output functions like fprintf(), fscanf(), sprintf(), sscanf(), etc. These are used to read and write data from and to a file or a string respectively.
It's worth noting that these functions are not type safe, and if the format string doesn't match the type of the variables passed to it, it may lead to undefined behavior. C-operator