0% found this document useful (0 votes)
5 views

Internship notes

Uploaded by

rajpriyanshu1195
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Internship notes

Uploaded by

rajpriyanshu1195
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

PREPROCESSOR:

In C or C++ language everything is defined by # is called preprocessor.


eg:-
#include : for including header files
#define : it is used to define macro.
#pragma : it is used for create padding.

GCC: GCC stands for "GNU compiler collection" it is a collection of libreary's and
header files which is used to compile a C program.

Internally every .C file convert into Expendable file [.i] first.

1.Source code: In c language file saved with [.c] format is called source code.

2.Expandable file[.i]:
every [.c] file converted into [.i] called Expandable file.

-During creation of [.i] file compiler replace the code of the header file with
there actual code.

-to convert source file to Expandable file We need to use this command gcc -E
file _name.c -o file_name.i

3.Assembly code [.s]:


Assembly code is created by compiler if it needed.

-Expandable file is converted into Assembly code.

-to convert [.i] to [.s] We can use following command.


gcc -s file_name.i -o file_name.s

4.Object file[.o]:
Assembler file is converted into object files.

-one or more than one file can be created by one Assembler file.
-linker is use to integrate all object file and create and executable file.

-to convert [.s] file to [.o] file we can use following command:
gcc -c file_name -o file-name.o

5.Executable file [.exe]:


Finally object file is converted into Executable file by linker.

-[.exe] file is also called an Application.

-to convert [.o] file to [.exe] We can use following command.


gcc -v file_name -o file_name.exe

TCC:

TCC:- stands for "Tiny c compiler".

VARIABLES:

variable is like a container which is used to store any type of data.


-It is a name of memory location.

=Initilization: Assigning some value to variable.


-Re initialization is allowed.

Syntax:
variable_name=value;
eg:-
x=23;
ch='A';

=Definition/Declaration: Declaration statement say's compiler to reserve memory


block for particular variable.

Syntax:
data_type variable_name;

eg:-
int x;
bool y;
float cgpa;

-two types of declaration is possible:


1.During Compile time
2.During Run time

Initilization and Decleration:


when definition and initialization is done in the same time then it is called
Initilization and Decleration.

Syntax:
data_type variable_name=value;

eg:-
int num=12;
int float=34.4;

Scope:
variable is define inside curly brackets{ }. and it is called the scope of
variable.
-variable is destroy outside the scope.

Global Variable:
The variable which have scope entire the program.
Local Variable:
variable which scope is fixed inside program.

To define variable name there have some specific naming rules:


1. Variable name can not start with number.
2. Variable name can contain alphabet and numbers to.
3. Variable name can not contain blank space.
4. We can use underscore '_' as a variable name only in special char.
5. Variable name is case sensitive.
6. We can not use keyword as a variable name.

int x1; valid


int x_1; valid

int_1; valid

int_1_1; valid

int x y; invalid

int x-y; invalid

int 3x; invalid

int x$; invalid

int if; invalid

int IF; valid

int string; valid

Input/output:

printf():
printf() function is use to print some output into consol window.

-everything inside printf written inside "", double codes.


-It return number of character it will print.

scanf():

scanf() function is ude to take input from user.

-Am-percent sign '&' is use to get the addres of particular memory location.
-scanf() takes formated input from the user.
-you can take more then one input at a time using scanf() function.

Seperaters:
usually next line or blank space is use as seperater otherwiswe we can
use any special character or seperater inside scanf().

STORAGE CLASS:
In C language we can store data inside different hierarchy of
computer memory.

In any computer system there are mainly 4 memory levels:-


Register
Catch
RAM
Secondary memory

1. auto:

auto keyword in c language is refers to automtic variables,it store inside


stack or Primary memory.
-auto is define in c/c++11.

Syantax:
auto variable_name; //definition
auto variable_name=value //definition and initilization

2.extern:
extern keyword says compiler to the variable is define somewere else in the
program or another file.

Syntax:
extern variable_name;

3.Static:
static keyword tells compiler to store variable inside stack.
-static keyword always decleared once in a program.

Syntax:
satatic data_type variable_name;

4.register:
register keyword says compiler to allocate memory in register for
particular variable.
-It was not possible to store data in register everytime.

Syntax:
register data_type variable_name=value;

Format Specifier:
It is use to define format of data type:
%d : int
%u : unsigned int
%f : float
%c : char
%s : string
%o : octal value
%p : address in hexadecimal
%lf : double
%lu : unsigned long
%llu : unsigned long long

DATA TYPES:
Data Types refers to types of data in computer science.

There are mainly two type of data is present:


1. Primitive:
It is a data type which doesnot depend on another data type.

eg:-
short (size of short is 2 byte)
int (size of int is 2^32)
unsigned int
long
long long
float (size of float is 4 byte)
double (size of double is 8 byte)

2. Non-Primitive:
Its depend on primitive data type.
String,Array,Pointer

3. User-defined data type:


It is a data type defined by user.
eg:-
structure,enum,union

OPERATORS:
Operators are the operations performs between one or more then one
operands.

There are mainly three types:

1. Unary Operator:
These are the operators use with only one operand.
eg:
+,-,++,--,!,~,sizeof()

Incrementor operator:
Incrementor operator is use to increase value by one.

They are of two types:-

(i). pre-incrementor:
It increase value first then assign.
eg:
++x,++y,++z;
(ii). post-incrementor:
It assign value first then increase the value of
var.
eg:
x++,y++,z++;

Decrement Operator:
Decrement Operator reduce the value of variable by one.
-decrement operator only valid for variables not for
constant.
-decrement operator are of two types:-

(i). Pre-Decrement operator:


This operator reduces value
first and then assign.
eg:
--x,--y,--z;

(ii). Post -decrement operator:


this operator assign value
first and then reduce by 1.

2. Binary Operator:
This are the operators used with two operands.
eg:
+,-,*,/,%,&(AND),|(OR),^(XOR),<<(Left shift),>>(Right
shift)

-x % 10 would return 7, which is the remainder after


dividing 27 by 10.
-x /10 would return 2, which is the quotient after
dividing 27 by 10.

-Bitwise AND(&):
It return 1 when both bits are 1.

b1 | b2 | b1&b2
-----------------------------|------------|--------------------
0 | 0 | 0
1 | 0 | 0
0 | 1 | 0
1 | 1 | 1
| |

-Bitwise OR(|):
It return 1 when at least one bit is on.

b1 | b2 | b1&b2
------------------------------|----------|------------------------
0 | 0 | 0
1 | 0 | 1
0 | 1 | 1
1 | 1 | 1
| |

-Left shift operator( << ):


This operator shift all bit left side by one position.
ex:-
10 << 2 = 40;
10 << 3 = 80;

Q.) 10 << 2

1 0 1 0
1 0 1 0 0
1 0 1 0 0 0

-Right shift operator( >> ):


This operator shift all bit right side by 'n' number of times.
ex:-
10 >> 2 = 2;
32 >> 3 = 4;

-Logical AND( && ):


It return true when both condition's are true.
Syntax:-
condition1 && condition2;

-Logical OR( || ):
It return true when atleast one comndition is true.
Syntax:-
condition1 || condition2;
-Comparision Operator:

> (Greater than),


< (Less than),
>= (Greater than and equal to),
<= (Less than and equal to)
!= (Not equal to),
== (equal to)

-Assignment operator:

= (equal to)
+= (plus equal to)
-= (minus equal to)
/= (divide equal to)
*= (multiply equal to)

3. Ternary Operator:
Ternary operator is operate with three operand.

Priority and Associtivity:

Operators Priority
Associtivity

!,~,++,-- 1 right to
left
*,/,% 2 left to
right
+,- 3 left to
right
<<,>> 4 left to
right

Conditional Statement's:
In C\C++ conditional statements is use to execute code with some
condition.

Syntax:

if( condition-1 ){

//this code is execute if first condition is true.


}
else if( condition-2){

//this code is execute if second condition is true.


}
else{

//this code is execute if not any condition is true.


}
-we can use if without any else condition.
-but we can not use else without if condition.
-we can not use else if without if condition.
-If we not provide any curly bracket then compiler by default run single line of
code.
-we can not use break statement inside conditional statement if-else.

You might also like