# C Language cheat sheet
**aim:**
> 1. to add some value in our *resume* and show Teamwork our Skills to recruiter.
> 2. this blog will help many first year students + learners
> 3. this blog will uploaded on DEV.to So more people will interact
> 4. this blog will help us to revise C in less time
> 5. any of our team member can use this blog and this markdown but (fair credits should be given)
plese find this [Link](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet)
or copy paste this url directly in your browser.
**https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet**
**please find this [Resource](https://kupdf.net/downloadFile/5985fac3dc0d609a11300d19) and TRY TO USE it!!! or write your OWN words.**
# TOC + MAP
> **Some words+motivation for Biginers Goes here!+**
> **PDF Link to download(Putting first so pps can Download it)**
# Hunaid Nakhuda <a name="hunaid-1"></a>
# Introduction
## **Environment Setup**
To set up your environment for C programming language, you need the following two software tools available on your computer,
(a) Text Editor
(b) The C Compiler.
- [ ] Environment Setup
- [ ] Program Structure
# Variable:-
variable names may consist of letters,digits,and the underscore(_)
some rules to define variables:-
1.They must begin with a letter. Some system permit underscore as the first character.
2.ANSI standard recognizes a length of 3 charecters.However, length should not be normally more than eight characters.
3.Variable names are case sensitive.
4.It should not be a keyword.
5.White space is not allowed
- [ ] Constant
- [ ] Keywords
- [ ] Data type
- [ ] Printf ScanF
- [ ] Operator
# Dinky Lakhani
- [ ] **If else**
<!-- start writting from here -->
There are numerous conditions that can be used to compare two variables and execute a certain piece of code based on the condition satisfied .
Following are few conditions :
| Particulars | Operators |
| ------------- |:-------------:|
| Equals | == |
| Not Equal | != |
| Greater than | a > b |
| Less than | a < b |
| Greater than or equal to | a >= b |
| Less than or equal to | a <= b |
These conditions can be used in several ways . One of which is using <span style="color:crimson;">```If-else```</span> statements.
**If statement:**
```
int main()
{
int a = 5;
int b = 20;
if (b > a)
printf("b is greater than a");
return 0;
}
```
In the above code , if b is greater than a will be true and the output will be :
```b is greater than a```
**If - else if statement:**
```
int main()
{
int a = 5;
int b = 5;
if (b > a)
printf("b is greater than a");
else if(a==b)
printf("a is equal to b");
return 0;
}
```
In the above example , the first condition turns out to be false and the control reaches to **```else if ```** statement . Thus , the output is
```a is equal to b```
**If - else statement:**
```
int main()
{
int a = 5;
int b = 3;
if (b > a)
printf("b is greater than a");
else if(a==b)
printf("a is equal to b");
else
printf("a is greater than b");
return 0;
}
```
In the above example , the first and the second condition turns out to be false and the control reaches to **```else```** statement . Thus , the output is
```a is greater than b```
- [ ] **Nested if**
<!-- start writting from here -->
If there is an ```if``` statement inside another **if** statement , it is known as nested if statement.
**Nested If - else statement:**
```
int main()
{
int a = 5;
int b = 3;
int c = 10;
if (a > b)
{
if(a>c)
printf("Maximum is a = %d",a);
else
printf("Maximum is c = %d",c);
}
else
{
if(b>c)
printf("Maximum is b = %d",b);
else
printf("Maximum is c = %d",c);
}
return 0;
}
```
The output of the above code is :
``` Maximum is c = 10```
The first if condition is true so the control moves inside it and the nested if condition becomes false so the else condition is executed.
- [ ] **Switch**
<!-- start writting from here -->
The switch statement is used to select one of the many blocks to be executed.
```
int main()
{
int month = 5;
switch (month) {
case 1:
printf("January");
break;
case 2:
printf("February");
break;
case 3:
printf("March");
break;
case 4:
printf("April");
break;
case 5:
printf("May");
break;
case 6:
printf("June");
break;
case 7:
printf("July");
break;
case 8:
printf("August");
break;
case 9:
printf("September");
break;
case 10:
printf("October");
break;
case 11:
printf("November");
break;
case 12:
printf("December");
break;
default:
printf("Error");
exit(1);
}
}
```
The output of the above code is **```May```**
In the above code , the switch statement evaluates the expression passed into its corresponding parenthesis.
The output of the evaluation is used by the case . If there is a match in the case statements , the code following it is executed and the <span style="color:orange;">break</span> keyword helps in exit from the switch statement.
Whereas, the <span style="color:green;">default</span> statement is executed if no match is found .
**NOTE
``` Default statement must always be placed at the end of the switch statement.```**
- [ ] **For loop**
<!-- start writting from here -->
When we know how many times a particular piece of code is to be repeatedly executed, the <span style="color:crimson;">for loop </span> is used.
Its syntax is as follows :
```
for(expression 1 ; expression 2 ; expression 3)
{
//code to be repeatedly executed
}
```
<u>*expression 1*</u> is called the initialization statement to set the beginning offset of the loop
<u>*expression 2*</u> is called the test condition statement to check for the continuation of the loop . It is also known as the <u> **exit condition**</u>.
<u>*expression 3*</u> is the statement that gets executed every time after the loop gets executed . It is usually an increment or decrement statement.
For e.g. :
```
int main()
{
int i ;
for(i=0;i<10;i++)
{
printf("%d",i);
}
return 0;
}
```
The output of the above code is :
**```0123456789```**
The iterator i is initialised with 0 and the test condition is checked . 0 is printed and the value of i gets incremented . Now , the value is <span style="color:crimson;">i=1 </span> . As it is less than 10 , the printf statement gets executed. This process keeps on repeating until the value of i becomes 10.
Since , 10 is not less than 10 , the loop stops.
**<u>Infinite Loop</u>**
If a user forgets to either increment/decrement the iterator or it forgets the exit condition , the loop gets repeated for an infinite number of times .
This is an error and may sometimes crash the system.
E.g. :
```
for(;;)
{
printf("hello world! ");
}
```
Observe the loop carefully . None of the conditions are mentioned and thus it will print <span style="color:violet;">hello world! </span>for infinite time period till user explicitly stops the execution.
- [ ] **While loop**
<!-- start writting from here -->
When we are not aware of the number of times the loop is to be repeated , the <span style="color:blue;">while</span> loop is used.
While loop gets executed as long as the condition is true .
**Remember** to initialize the iterator at the beginning of the while loop and to increment/decrement the iterator (for exitting the loop) inside the while loop (preferrably at the end of while loop).
The syntax for the same is illustrated with an example as follows :
```
int main()
{
int i = 0 ; //initializing iterator
while(i<10) //test condition
{
printf("%d",i);
i++; //increment statement
}
return 0;
}
```
The output of the above code is :
**```0123456789```**
**<u>Infinite Loop</u>**
If the condition is always <span style="color:orange;">true </span> rather it never becomes **false**, the loop gets repeated for an infinite number of times .
This is an error and may sometimes crash the system.
E.g. :
```
char ch = 'a';
while(1)
{
printf("%c",ch);
}
```
The condition following the while is always true i.e while it is 1 and thus it will print <span style="color:violet;">aaa....</span> infinite times till user explicitly stops the execution.
- [ ] **Do while**
<!-- start writting from here -->
The <span style="color:aqua;">do while</span> is similar to while except that it gets executed atleast once before checking the condition and the loop is repeated as long as the condition is true.
**Note** the semicolon at the end of the loop
The syntax of the loop is illustrated with an example as follows:
```
int main()
{
int i = -1 ; //initializing iterator
do
{
i++; //increment statement
printf("%d",i);
}while(i<0); //Test condition
return 0;
}
```
The output of the above piece of code will be :
**```0```**
- [ ] **Nested loop**
<!-- start writting from here -->
Sometimes called as <u>**"Loop inside Loop"**</u>.
There can be any combination such as for loop inside another for loop , while inside while , do while inside another do while .
There can also be hybrid nested loops i.e. while inside for and similar combinations .
For e.g. :
```
int main()
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
printf("%d ",i*j);
}
printf("\n");
}
return 0;
}
```
The output will be :
```
0 0 0
0 1 2
0 2 4
```
## Vivek Patel
## Array
- An array is fixed-size sequenced collection of elements of same data type.
- it is data structure that can stores a fixed-size sequential elements of same Data type.
**Types of arrays**
1. One-dimentional arrays
2. Two-dimentional arrays
3. Multi-dimentional arrays
//photo array variable and index
One Dimentional arrays
//Photo 1d arrays
define : datatype array_name[size];
It must be a valid identifier and should follow veriable declaration rules
```
int a[99];
float point[20];
char name[50];
```
* num is an array of type int, which can only store 99 elements of type int.
* x is an array of type float, which can only store 20 elements of type float.
* name is an array of type char, which can only store 50 elements of type char.
- [ ] md array
- [ ] typedef and #define
- [ ] Function
- [ ] String functions
- [ ] Math functions
## SoumyaDeep Ghosh
- [ ] Structure
- [ ] Union
- [ ] Enum
- [ ] File handling
- [ ] Graphics
- [ ] Malloc and calloc
again pdf, Credits here ,,Thanks,Final Words from team.
Resources Used in blog : https://www.amazon.in/dp/B076Y39SHL/ref=cm_sw_em_r_mt_dp_502V7XH78C52KBEDGSV3?_encoding=UTF8&psc=1