Comments are ignored by the compiler. We can comment in two ways. 1) Single line comment, start with // ; 2) Multiple line comment. They start with /* and ends with the */. We can also use it for single line comment.
/* single line comment */
// single line comment
/* multiple line comment.
This is my 1st program.
Identifier is a name, which is used to identify a variable, function, or any other user-defined item. It is started with a letter a to z, A to Z, or an underscore ‘_’ followed by zero or more letters, underscores, and digits (0 to 9).
C language does not allow some characters such as %, $, and @ within identifiers. It’s a case-sensitiveprogramming language. Thus, Himuand himu are two different identifiers. Here are some examples of acceptable identifiers −
mhud john def next_name c_193
urname50 _name a j93b9 petVal
auto break case char const continue default do double else
enum extern float for goto if int long register return
short signed sizeof static struct switch typedef union unsigned void
while volatile _Packed
The above list shows the reserved words in C. We can’t use these words as variables or constants or any other identifier names.
Variables in C Programming Language
Variable is used to store data, which is a name of memory location. We can reuse it many times; its value can be changed.
Syntax to declare a variable:
Example of declaring variable:
ü int m;
ü float n;
ü char o;
We can also provide values while declaring the variables:
ü int m=10;
ü float n=20.8, p=10.3; //declaring 2 integer float variable
ü char o=’K’;
ü C language.
Data Types in C Programming Language
|| Data Types
|| int, char, float, double
|| array, pointer, structure, union
Operators in C Programming Language
An operator is a symbol which is used to perform operations. There are many types of operations. Like bitwise, assignment, arithmetic, relational, logical, shift, bitwise, ternary or conditional Operator, misc Operator
The following are arithmetic operator.
+, −, *, /, %, ++, —
The following are Relational operator.
==, !=, >, <, >=, <=
The following are Logical operator.
And: &&, or: ||, not: !
The following are Bitwise operator.
&, |, ^, ~, <<, >>
The following are Assignment operator.
=, +=, -=, *=, /=, %=, <<=, >>=, &=, ^=, |=
The following are Misc operator.
sizeof(),&,pointer: *, ? :
The following is Conditional operator.
Constants in C Programming Language
We can define constant in 2ways.
1. const keyword
const float PI=3.14;
2. #define preprocessor
#define token value
#define PI 3.14
printf() & scanf()
To print something/output, we have to use printf()function. And if we need to input something from user we need to use scanf() function. Both function are defined in stdio.h (header file). We also called them build in function.
The syntax of printf()& scanf() function:
printf(“My name is Crazy Programmer.”);
Output: My name is Crazy Programmer.
Here format_string is %d / %s / %c etc.