Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
29 views
C++ Notes
Uploaded by
shruthiiichikki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save C++ Notes For Later
Download
Save
Save C++ Notes For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
29 views
C++ Notes
Uploaded by
shruthiiichikki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save C++ Notes For Later
Carousel Previous
Carousel Next
Download
Save
Save C++ Notes For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 13
Search
Fullscreen
(ARRAYS) * Single unit 05 multiple values: «A fixed size collection OG tems with same datatype » Hemogenaus collection. Storage 7 Arvay is stored sequentially in meniory. -? Contiguous Memory 3 *.a chunk of memory allocated without any gaps in the addvesses it occupies + One single unbroken " black” °f memory. What (fF memery is non- contiguous :- * viel An away is p6ficontiquous as it is an indexed based dato structure. In absence contig to create an ayray- An enor will be thrown. vous Space available in MeEMOrY,. Program wil) fel. Declaration : Dalatype Arvayname [ int - expression] avray subscripting fat array Var 4. eye eperator- Datatype atray narne Size (Sze mst be integer os ¢t is the count of array elements ) Memory View : arrayVay 4. [oJ Ue) orray Ver 4 [4] 20 Size 5 arvayVay 4 [2] 30 away Var 4 [33 4o avvay Vay 4. [4] 50 / Index¢ More than one ayray can be declared ona Sine: tnt student [10], Faculty [30] , Player [20] 5 « Aways can be declared alongwith the declaration 06 voriables. int var, var 2, marks [8] 5 Inikalizers = Elements of array. int £5] = §1523,4.5}5 aay initializers 'F size is not provided during declovation, initializes will determine the size. Limitations of arrays =. ° We must know how many elements are to be stored in orray e Array is static Structure with pixed size, so the memory allocated to array cannot be changed: 0 As the memary is contiguous, insertion and deletion is ‘difficult and Hime consuming. Types oh arroys : ARRAY Muli one two dimensional dimensional dimersionalA (2D-ARRAYS) * Arrays with 2 or more dimensions * Covrespord to matrices 1D arrays —> List 2D arrays —> Table Definition: * A fixed size collection of items off same data type arranged fn two dimensions- © 2D arrays can be considered 95 a table with rows and columns. e Each element 06 2D array ts referred. to with help 06 2 indexes. 4 index indicates row and 2 index indicates column- Declaration : Mt myarray [2](3] 5 data. Column type array subscript hame Row subscript —> int myAray (3) [2] = {£12016}, {22,525}, {32035}} W column O column 4 Row O 12 15 Row 1 2! 25 Row2 32 35(FUNCTIONS) + Problem solving approach for complex [forge problerns + Basic Rule — Divide and Conquer v : division of forge problem into smaller parts and then solving them Definition :- A function groups a number 6 prograny statement into a unit and gives tt a name. « Dividing a progyary into Bunctions is. one of the major principle h Structured Programming. . Every Ct progrann hos atleast one fercton, thot 1s maint) Advantages :- Using unctions in a program is very beneficial ond is considered a good approach: Following ave Listed some advantages OB Benctions + » Avoid repetition of samme code in program. > Improve readibility of program. & Make program modification easier- & Debugging becores easier. & Mulkiple persons can work on the program (on seprate functions) Types: 2 types of functions iin c++. Function pre- defined. user-definedpre- -defined function +- Functions that Ctt fs alreddy Providing to users through different braries - pre-defined functions are organized into seprate Bibyories . + For input ond output functions, fostream ts available- + For all math Genctions, cmath is available. examples are : «clyscr () — cleay screen = pow () — power = sat (26) — saqvare root user-defined function +- Furckons that ave created by users according to the requirements - : €-g+TO find sun 0B 2 numbers Calculate income tax USER DEFINED FUNCTION oP oS value vetuning votd Benction benction e Value returning Benction + These fyrctions have a return type- They must > ¥elurn some valve of) a specific data type. © Void. function : These Gunctions dont have any retum type They dont use return statement to retum a value.USER DEFINED FUNCTIONS Functions created by user according fp requirements: Components : + Function declayation ( prototype) ¢ Furction definitfon ¢ Funchon callt- syntax of cormponents : Decloyation returtype functon.name ( porameters) Colt forction.. name ( parameters) Depinitfon relum. type function name (porarneters ) f statements 5 Declavation :- « Function declaration provides information to compiler by telling its relum type» parameters {datatypes and function name - * Declaration is followed by a Semicolory (5) * Declaration is required When a fyrcton is defined betow or apter its call: In this case, funcHon should be declared before call. int sum (int x> int y) $$ ais / return type semicolon furction porameters hameDefinition De « Function bady is called its definition. elt tells the actual Bunctonabty and Logic of program. elt actually informs what the Buncton will do in program . NY irop If forction is defined. before its call, then its definition also serves as tts declarakon, so a prototype (seprate) is unnecessary. But 16 function is defined apter its call, then prototype is necessary before call int_sunn (int x» int) > obo acts os declorator statements 3 —> body of, function. } Return type > Retum type is the data type of value Hat function returns- Parameters —> It is just Sike a placeholder. We pass actual values to these Parometers during function calf: Those actual valves are called as ‘arguments’ In Ctty you give a definition of what a function has to do yank then to use that bunction , you will hove to call that function Wn Burchon calf, you have to pass the actual values (arguments) instead H the povometers used in definition sum (arguments) 5 a. Fonction name semicolon arguments to be passed.(POINTERS) Pointeris a vorioble that holds the memory address of) another variable Normal Vorable <> use to Stove values of their type.Cdivect veference) Pointers => use to Store address cf voriable. (indivect reference) Memory address :- Location of another vorioble where it has been stored. tn the memory. + pointer holds the address of a Variable, we eax say that it points to thot variable: Declaration : Must be declared before their usage- * Stas datatype variable — name 5 + Int®x (pointer to int) + float * ptr (pointer to Foot) + char*z (pointer to chor) Address operator (&) « Address operator (8) is used tp produce an address of voriable by Operating on voriable name- « If we wont to refer to address ofa particulor varable, we con use the address operator var 4 vert —> This will give the oddress Dereferencing operator (*) © unary operator thot operates function on poinfer voriable- 2 We can access the value stored in the variable through dereferencing Operator: « It retums the contents of variable Located at specific address- float* ptr;const pointer | non constont data : Pointer ‘tselg is constants but the value t's poinking to is non-constcer pointing towards Const: pointer :- pointer &s a specific voriable- Apter constant, the variable to which it is pointing becom cont’ be changed. ink x = 63 int * const ptr = &xs V~ ptr=ay; x Non- constant data :- As data is non-constant, so the value of, the Variable pointer is pointing to can be changed - int x= 63 int*const ptr = &X 5 vw Aptn= $5 const pointer / const data : pointer and the vorioble it is pointing to , beth are constant fint value = 55 const int * const ptr = & valve 5 Noither the address of, pointer can get chonge nor the valve it ts pointing to non-constant pointer /constont dato. pointer itself is not constant but the valve it is pointing to fs constant ard hixed- Non- constant pointer 2 As the pointer ts non-constant) it can point to multiple addresses. We can chonge the address: const int x = 55 consE int * ptr =bas |] const int y= 65 ogy ptr = &y3const - data + int x = 53 const int * ptr = &x 5 thiough pointer. X=65] 4 (RECAP) int x = 535 4: int * ptrd = &x 35 (non-constant pointer and non-constant dota) Dis const int* ptr2 = &% > (non- constant pointer and constont data) 3: int * constant ptr3 = AX 3 (constant pointer and non-constant data) 4: const int * const ptr4 = &X 5 ( constant pointer and constant data) data is constont, its value cannot be changed sptr= 63] x we cant? chonge the volvePOINTERS TO VOID General purpose pointers hat can point to ony datatype void ptr 5 POINTERS IN FUNCTIONS 3 methods for passing parameters fn fynetions e Pass by value e Poss by reference © Pointers Definition =- Void furction-name (datatype * ptrvor) 5 Cal :- function- rame (& var_nome) 3Static Memory Allocation « Aso called as Compile Hime allocation «size and Location where variable will be pexee Stoved. fs fixed during compile Lime. * Both alfocabin and dellocakion Of, memory is done by wmpiser rtself- + shigyily faster * memory allocaben on Stack. DMA New operator e used {0 allocate memory bo a variable @ pointer is used to allocate memory Hyrami cally. ® pointervarfable = new datatypes Dynamic Memory Allocation. + Mso cabled os Ruun time calfocation + Memory yequirement Should be rey olepined during the execution 08 program . © Programmer needs to write proper code ber alfocatin and delDocation. | ° sdigntSy sDower-. + memory alfocaHon on heap - Dalete operator used to deOlocate tte wemory occupied by variable. pointer is used to deagifocate ithe memory - delete potervariable sLOCAL VARIABLE Variable defined inside a Puretion body Its scope ts Limited to the Guretion where it ts defyined Is Lifetive ends viren the Byrction exits: GLOBAL VARIABLE Voriable depined globaulty , outside all Bunctions Its scope is the whole program: is Bife erds only when Yhe progrem ords STATIC LOCAL Also defined inside a Bunction- Its scope f th whole program from where it fs initial zad - lis Dife ends with the ending o§ program.
You might also like
Basic Constructs in C++
PDF
No ratings yet
Basic Constructs in C++
54 pages
Itp 6
PDF
No ratings yet
Itp 6
42 pages
Conceptofcdatatypes 090925045031 Phpapp02
PDF
No ratings yet
Conceptofcdatatypes 090925045031 Phpapp02
30 pages
Module 4 CSC 201
PDF
No ratings yet
Module 4 CSC 201
33 pages
6 Pointer
PDF
No ratings yet
6 Pointer
30 pages
Chapter 2 Pointers
PDF
No ratings yet
Chapter 2 Pointers
36 pages
Pointers
PDF
No ratings yet
Pointers
37 pages
Chapter 1 (1)
PDF
No ratings yet
Chapter 1 (1)
8 pages
chapter_9
PDF
No ratings yet
chapter_9
32 pages
CSC 218 Lecture Slides [Derived Types_array_pointer_vector_string]
PDF
No ratings yet
CSC 218 Lecture Slides [Derived Types_array_pointer_vector_string]
24 pages
Lecture3 Week 2
PDF
No ratings yet
Lecture3 Week 2
21 pages
Chapter 5 (Part I) - Pointers
PDF
No ratings yet
Chapter 5 (Part I) - Pointers
70 pages
Pointers in C++
PDF
100% (1)
Pointers in C++
39 pages
RDoc38062
PDF
No ratings yet
RDoc38062
25 pages
Chapter-2 DMA-1
PDF
No ratings yet
Chapter-2 DMA-1
65 pages
CP 111 Lecture 4 - DATA TYPES
PDF
No ratings yet
CP 111 Lecture 4 - DATA TYPES
45 pages
CSC404 Chapter1
PDF
No ratings yet
CSC404 Chapter1
45 pages
CSC-2077 -- Week_1
PDF
No ratings yet
CSC-2077 -- Week_1
43 pages
Pointers Dynamic Memory Part2 (1)
PDF
No ratings yet
Pointers Dynamic Memory Part2 (1)
64 pages
Oop M03
PDF
No ratings yet
Oop M03
64 pages
Polymorphism I
PDF
No ratings yet
Polymorphism I
63 pages
Computer - Science - Notes - CH04 - Pointers Notes
PDF
No ratings yet
Computer - Science - Notes - CH04 - Pointers Notes
10 pages
Pointer
PDF
No ratings yet
Pointer
57 pages
Pointers in C++
PDF
No ratings yet
Pointers in C++
62 pages
WINSEM2023-24 BECE320E ETH VL2023240504751 2024-03-11 Reference-Material-I
PDF
No ratings yet
WINSEM2023-24 BECE320E ETH VL2023240504751 2024-03-11 Reference-Material-I
79 pages
Pointers in C
PDF
No ratings yet
Pointers in C
67 pages
Dynamic Memory Allocation-1
PDF
No ratings yet
Dynamic Memory Allocation-1
38 pages
Unit 5 - I Pointers
PDF
No ratings yet
Unit 5 - I Pointers
24 pages
CS205-2020 Spring - Lecture 4 PDF
PDF
No ratings yet
CS205-2020 Spring - Lecture 4 PDF
45 pages
CIE 202 - Unit 03 - Pointers and Dynamic Memory
PDF
No ratings yet
CIE 202 - Unit 03 - Pointers and Dynamic Memory
51 pages
11 - Pointers and Files
PDF
No ratings yet
11 - Pointers and Files
92 pages
Procedural Concept: - The Main Program Coordinates Calls To Procedures and Hands Over Appropriate Data As Parameters
PDF
No ratings yet
Procedural Concept: - The Main Program Coordinates Calls To Procedures and Hands Over Appropriate Data As Parameters
29 pages
Unit6 Pointers 1
PDF
No ratings yet
Unit6 Pointers 1
80 pages
Pointer & Recursive Types
PDF
No ratings yet
Pointer & Recursive Types
38 pages
l7 Pointers
PDF
No ratings yet
l7 Pointers
59 pages
W3_OOP
PDF
No ratings yet
W3_OOP
38 pages
Lecture 7_Pointer
PDF
No ratings yet
Lecture 7_Pointer
19 pages
Pointers
PDF
No ratings yet
Pointers
28 pages
Lecture 1
PDF
No ratings yet
Lecture 1
45 pages
FOP-2 Question Bank Solutions Unit-1, 2, 3 & 4
PDF
No ratings yet
FOP-2 Question Bank Solutions Unit-1, 2, 3 & 4
33 pages
Session 6
PDF
No ratings yet
Session 6
94 pages
Lecture Notes CS1201 Part2
PDF
No ratings yet
Lecture Notes CS1201 Part2
108 pages
Revision C Ch1
PDF
No ratings yet
Revision C Ch1
72 pages
Discrete Structure 2
PDF
No ratings yet
Discrete Structure 2
225 pages
Ch10 - Pointers Revision
PDF
No ratings yet
Ch10 - Pointers Revision
27 pages
Pointers
PDF
No ratings yet
Pointers
62 pages
Short Notes On Dynamic Memory Allocation, Pointer and Data Structure
PDF
No ratings yet
Short Notes On Dynamic Memory Allocation, Pointer and Data Structure
25 pages
Data Structures_ Beginner's Complete Guide pt-00
PDF
No ratings yet
Data Structures_ Beginner's Complete Guide pt-00
27 pages
c assign part 1
PDF
No ratings yet
c assign part 1
25 pages
Pointers: Comp2115 - Information Structures Lecture Notes
PDF
No ratings yet
Pointers: Comp2115 - Information Structures Lecture Notes
7 pages
3 Pointers
PDF
No ratings yet
3 Pointers
26 pages
Pointers in C++
PDF
No ratings yet
Pointers in C++
22 pages
Chapter 2 Pointers in C++
PDF
No ratings yet
Chapter 2 Pointers in C++
44 pages
PF Lab 09 Manual
PDF
No ratings yet
PF Lab 09 Manual
8 pages
Standard C++ With Object-Oriented Programming BOOK CH 4
PDF
No ratings yet
Standard C++ With Object-Oriented Programming BOOK CH 4
51 pages
C++ Memory Map:: Pointers
PDF
No ratings yet
C++ Memory Map:: Pointers
10 pages
Pointers Old
PDF
No ratings yet
Pointers Old
51 pages
C++ From Beginner to Professional by Example (1)
PDF
No ratings yet
C++ From Beginner to Professional by Example (1)
410 pages