C and Basic Commands
First to deal with programming in C we need to understand the basic construct on how to run a program in C (check keynotes ,in the end portion, for better understanding or if are in a hurry and not interested into these basics)
Token
The smallest individual unit in a program is known as a Token
A character set is a set of alphabets, letters and some special characters that are valid in C language
This includes Alphabets, Digits (0,1,2,3,4,5,6,7,8,9) and Special Characters
Keywords are predefined, reserved words used in programming that have special meanings to the compiler. Keywords are part of the syntax and they cannot be used as an identifier. For example:
int money;
•Here, int is a keyword that indicates money is a variable of type int (integer).
- As C is a case sensitive language, all keywords must be written in lowercase. Here is a list of all keywords allowed in ANSI C(American National Standards Institute Codes)
C Keywords
auto double int struct
break else long switch
case enum register typedef
char extern return union
continue for signed void
do if static while
default goto sizeof volatile
const float short unsigned
Identifier refers to name given to entities such as variables, functions, structures etc.
Identifiers must be unique. They are created to give a unique name to an entity to identify it during the execution of the program. For example:
int money;
Double accountBalance; Here, money and accountBalance are identifiers.
Also remember, identifier names must be different from keywords. You cannot use int as an identifier because int is a keyword.
In programming, a variable is a container (storage area) to hold data.
Variable: To indicate the storage area, each variable should be given a unique name (identifier). Variable names are just the symbolic representation of a memory location. For example:
int playerScore = 95;Here, playerScore is a variable of int type. Here, the variable is assigned an integer value 95.
or say float money = 120.5. Here money is a variable of float type(decimal). 120.5 is the value assigned to it.
The value of a variable can be changed, hence the name variable.
Literals are data used for representing fixed values. They can be used directly in the code. For example: 1, 2.5, ‘c’ etc.
Here, 1, 2.5 and ‘c’ are literals.
You cannot assign different values to these terms
Constants: If you want to define a variable whose value cannot be changed, you can use the const keyword. This will create a constant. For example,
const double PI = 3.14;Notice, we have added keyword const.
Here, PI is a symbolic constant; its value cannot be changed.
const double PI = 3.14; PI = 2.9; //Error
What is a command in programming?
A command (in simple words) is a directive to a computer program to perform a specific task
Or like an event in a graphical user interface triggered by the user selecting an option in a menu.
Say in a hypothetical situation, A ship is sailing in a sea and suddenly there is a turbulence and the captain(or commander) decides to halt the ship to the nearest island and commands so to the sailors. Here the turbulence acts as a trigger making the commands work to reach the objective.
To make a program run, the program itself needs a set of values to work with and commands to execute the program.
C Basic commands and it’s Explanation
#include <stdio.h> : This is a preprocessor command that includes standard input output header file (stdio.h) from the C library before compiling a C program
main(): This is the main function from where execution of any C program begins.
{ : This indicates the beginning of the main function.
} : This indicates the end of the main function
/*_some_comments_*/ : whatever is given inside the command “/* */” in any C program, won’t be considered for compilation and execution.
printf(“Hello_World! “); : printf command- prints the output onto the screen.
scanf(); : This command receives the value from the keyword.
getch(); : This command waits for any character input from keyboard.
return 0; : This command terminates C program (main function) and returns 0.
Some other C –commands
for: This command is used to construct loops.
SYNTAX: for( initialization ; test; increment) { statements; } where initialization is a statement that assigns the initial value to the indexing variable, test is a logical statement , increment is a statment to update the indexing variable, and statements are C code that is executed for that particular value of the indexing variable provided the test is true.
int : These assign memory of various types to variable name. The size of int (single precision integer data type) is 4 bytes
float : The size of float (single precision float data type) is 4 bytes
double : The size of double (double precision float data type) is 8 bytes.
Char is used for declaring character type variables. The size of the character variable is 1 byte.
Keynotes:
<1>printf is the counterpart of scanf
<2>int, float, double ,char assigns memory of various types to variable names.
< 3> float is used for decimal type data,
<4>Format Specifier: It is a way to tell the compiler what type of data is in the variable while taking input in scanf or printf.
<5>Syntax: Syntax is a set of rules that defines the structure of statements in a computer language.
<6> Stdio.h stands for standard input output and “.h” is the header extention
<7> conio.h is another header file standing for Console Input Output. User specific.
<8>math.h is another user special header specially used for mathematical programs.
c/o: PhiWhyyy!?! ❤
Information is collected from various sources, NO COPYRIGHT INFRINGEMENT IS INTENDED.