C IMPORTANT PROGRAMS - 1

In this course, you will learn about the basics of programming.

So, first of all the main question is why we are starting with C and not any other language? C is a procedural programming language. It was mainly developed as a system programming language to write an operating system. 

The main features of C language include low-level access to memory, a simple set of keywords, and clean style, these features make C language suitable for system programmings like an operating system or compiler development.

Things that this C blogs provides:

  1. Variables, keywords, modifiers
  2. Data types
  3. Operators
  4. Compile and run
  5. Flow of control
  6. Functions
  7. Recursion method
  8. Storage classes
  9. pointers
  10. Arrays
  11. Structures

-> variables, keywords, type specifier, etc...

Keywords are the certain syntax rule of C that have a unique meaning and these must not be used for any other purposes. For example: struct, const, 

Variables are the words defined by the user to store the memory. For example: int a; char b; char str[10]; etc


Type Specifier is used to specify the type of the input/output. For example: %d is used to specify integer type, %c is used to specify character, %f is used to specify decimal values.



->Data Types

The data types the type of output variable return. There are 2 types of data type namely predefined/fundamental data type and derived data types.
Fundamental data types are predefined by the programmer. For example: int, char, float, double and void.
Derived data types are defined by the user itself. These include Arrays, Structure, Class, Union, Enumeration, Pointers, etc.


->Operators

There are different type of operator present in C and I will give you brief about each and every type.
1. Arithmetic operator:- these are the operators which contains the basic arithmetic symbols. They are: +,-,*,/,%. Modulas (%) is use to find the remainder of 2 numbers.
2. Relational operator:- these operators defines the relation between 2 quantities of same data type. They are: >, <, =, <=, >=.
3. Logical operator:- these operators are used to find the logic between the two operators. They are: &&(and), ||(or) and !(not).
4. Unary operator:- these are the operators which will operate on only one operator. They are: ++ and --.


->Compile and run

Compilation is the most important part of any program. The statement that is used to compile the program is  gcc -o temporary_file_name original_file_name.c
For example: gcc -o h1 abc.c
To execute your program, you need to write the run statement
./temporary_file_name helps to execute. For example: ./abc


->Flow Of Control

It contains the statements which maintain the flow of the program. These contain 2 types of statement : selection statement and iteration statement.

Selection Statement are those which is used to select one option out of many options. It is of 2 types namely, if-else and switch.

Iteration Statement are those which is used to make a loop so that a single work can be done more than one time.

Calculator : Calc
Power consumption bill payment : Bill Payment
Find the bonus on the salary : salary
Nested if-else : nesting
Switch case : switch_case 
Odd and even number : odd_even
'*' pattern : pattern1
Pattern 2 : Pattern-2
Pattern 3 : Pattern-3
Pascal triangle : Triangle


->Recursion

The process of calling a function by itself is called recursion and the function which calls itself is called recursive function. It follows the method of Divide and Conquer.

Fibonacci series (simple) : Fibonacci_simple

Fibonacci series (recursion) : Fibonacci_recursion
GCD (simple) : gcd_simple
GCD (recursion) : gcd_recursion
Factorial (simple method) : Factorial normal
Factorial (recursion method) : Factorial recursion

Call by value:- It is the method to call a function. In this we pass the values of variable at the time of calling.

Call by reference:- In this method, instead of passing value we pass the location/address of the variable.

Swapping two variable(call by value) : Swap1

Swapping two variable(call by reference) : Swap2

->Pointers

Pointers are the variables that points to the address of another variable. They use to point to another variable's address and create a link between them. Example: int *a; int b=1;   a=&b;
The line:"int b;" tells the compiler to:
1> Reserve space in memory to hold the integer value.
2> Associate the name b with this memory location.
3> Store the value 1 at this location.

Each and every consists of 2 parts: R-value and L-value.
R-value is the value that is assigned by the programmer to the variable.
L-value is the value that is assigned by the computer to the variable. It is the storage address of the variable in the memory. Remember that *(&a) is same as a.

Basic pointer code : p1

Pointer explain : p2
output_of_p2
explaination

You can find more program which is uploaded in the second part of this post๐Ÿ‘‰๐Ÿ‘‰ Part - 2

Download it in the pc and execute. If you have any doubt or problem kindly mention it in the comments.

Comments