SlideShare una empresa de Scribd logo
1 de 25
UNIT-5
Files & Pointers
MCA-2nd
Sem
Basic Input /Output
stream description
cin standard input stream
cout standard output stream
cerr standard error (output) stream
clog standard logging(output)
stream
Standard output (cout)
cout << "Output sentence"; // prints Output
sentence on screen
cout << 120; // prints number 120 on
screen
cout << x; // prints the value of x
on screen
cout << "Hello"; // prints Hello
cout << Hello; // prints the content of
variable Hello
Standard input (cin)
int age;
cin >> age;
i/o example :
#include <iostream>
using namespace std;
int main ()
{
int i;
cout << "Please enter an integer value: ";
cin >> i;
Standard input (cin)
cout << "The value you entered is " << i;
cout << " and its double is " << i*2 << ".n";return0;
}
O/P:-
Please enter an integer value: 702
The value you entered is 702 and its double is 1404.
Read/write modes in C++.
Reading A File
#include <fstream.h>
void main() {
ifstream OpenFile("cpp-home.txt");
char ch;
while(!OpenFile.eof())
{
OpenFile.get(ch);
cout << ch;
}
OpenFile.close(); }
Read/write modes in C++.
Writing A File
#include <stdio.h>
#include <string.h>
int main(int argc, char * argv[])
{
const char * filename="test.txt";
const char * mytext="Once upon a time there were
three bears.";
int byteswritten=0; FILE * ft= fopen(filename,
"wb") ;
Read/write modes in C++.
  if (ft) 
{   
 fwrite(mytext,sizeof(char),strlen(mytext), ft) ;  
 fclose( ft ) ;   
}
 printf("len of mytext = %i ",strlen(mytext)) ;  
 return 0;
 } 
Declarations, Referencing and
dereferencing
#include<iostream>
 using namespace std;
 void main()
 {
 int x;
 int *ptr_p; x = 5; 
 ptr_p = &x;
 cout << *ptr_p; 
} 
In the example above we used ampersand sign (&). This 
sign is called the reference operator.
Reference and dereference operators
 In the example above we used ampersand sign (&). 
This sign is called the reference operator. 
 If  the  reference  operator  is  used  you  will  get  the 
“address of” a variable.
  In the example  we said: ptr_p = &x;. In words: store 
the address of the variable x in the pointer ptr_p.
Reference and dereference operators
 We  also  used  the  asterisk  sign  (*)  in  the  cout 
statement.  This  sign  is  called  the  dereference 
operator. 
 If  the  dereference  operator  is  used  you  will  get  the 
“value pointed by” a pointer. 
 So cout << *ptr_p;. In words: print (or put into the 
stream) the value pointed by ptr_p. (It will print the 
contents of integer x.)
Reference and dereference operators
Reference and dereference operators
The  address  of  a  variable  can  be  obtained  by 
preceding the name of a variable with an ampersand 
sign (&), known as reference operator, and which can 
be  literally  translated  as  "address  of". 
foo = &myvar;
myvar = 25;
foo = &myvar; 
bar = myvar;
Reference operator
1.First,  we  have  assigned  the  value 25 to myvar (a 
variable  whose  address  in  memory  we  assumed  to 
be 1776).
2.The  second  statement  assigns foo the  address   
of myvar,  which  we  have  assumed  to  be 1776.
3.Finally,  the  third  statement,  assigns  the  value 
contained  in myvar to bar.  This  is  a  standard 
assignment operation, as already done many times in 
earlier.  .
Reference operator
4.The main difference between the second and third
statements is the appearance of the reference
operator (&).
5.The variable that stores the address of another
variable (like foo in the previous example) is what in
C++ is called a pointer.
Dereference operators
 An interesting property of pointers is that they can be
used to access the variable they point to directly. This
is done by preceding the pointer name with
the dereference operator (*). The operator itself can
be read as "value pointed toby”.
baz = *foo;
 This could be read as: "baz equal to value pointed to
by foo", and the statement would actually assign the
value25 to baz, since foo is 1776, and the value
pointed to by 1776 (following the example above)
would be 25.
Dereference operators
Dereference operators
 It is important to clearly differentiate that foo refers
to the value 1776, while *foo (with an
asterisk * preceding the identifier) refers to the value
stored at address 1776, which in this case is 25.
 Notice the difference of including or not including
the dereference operator (I have added an explanatory
comment of how each of these two expressions could
be read):
Dereference operators
 & is the reference operator, and can be read as
"address of“
 * is the dereference operator, and can be read
as "value pointed to by"
•
Passing Pointer to functions,
 To call the function pointed to by a function pointer,
you treat the function pointer as though it were the
name of the function you wish to call.
 The act of calling it performs the dereference; there's
no need to do it yourself:
Passing Pointer to functions,
#include <stdio.h>
void my_int_func(int x)
{
printf( "%dn", x );
}
int main()
{
void (*foo)(int);
foo = &my_int_func;
foo( 2 );
(*foo)( 2 );
return 0; }
Pointer to Arrays
#include <iostream>
using namespace std;
const int MAX = 3;
int main ()
{
int var[MAX] = {10, 100, 200};
int *ptr[MAX];
for (int i = 0; i < MAX; i++)
{
Pointer to Arrays
ptr[i] = &var[i];
}
for (int i = 0; i < MAX; i++)
{
cout << "Value of var[" << i << "] = ";
cout << *ptr[i] << endl;
}return0;
}
Pointer to Arrays
OUTPUT:
Value of var[0] = 10
Value of var[1] = 100
Value of var[2] = 200
REFRENCES
• Learn Programming in C++ By Anshuman
Sharma, Anurag Gupta, Dr.Hardeep Singh,
Vikram Sharma

Más contenido relacionado

La actualidad más candente

Pointer Basics,Constant Pointers & Pointer to Constant.
Pointer Basics,Constant Pointers & Pointer to Constant.Pointer Basics,Constant Pointers & Pointer to Constant.
Pointer Basics,Constant Pointers & Pointer to Constant.Meghaj Mallick
 
Learning C++ - Functions in C++ 3
Learning C++ - Functions  in C++ 3Learning C++ - Functions  in C++ 3
Learning C++ - Functions in C++ 3Ali Aminian
 
Lecture#6 functions in c++
Lecture#6 functions in c++Lecture#6 functions in c++
Lecture#6 functions in c++NUST Stuff
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2rohassanie
 
Function overloading(C++)
Function overloading(C++)Function overloading(C++)
Function overloading(C++)Ritika Sharma
 
C++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIAC++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIADheeraj Kataria
 
Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)Dharma Kshetri
 
FP 201 - Unit 6
FP 201 - Unit 6FP 201 - Unit 6
FP 201 - Unit 6rohassanie
 
Learn c++ (functions) with nauman ur rehman
Learn  c++ (functions) with nauman ur rehmanLearn  c++ (functions) with nauman ur rehman
Learn c++ (functions) with nauman ur rehmanNauman Rehman
 

La actualidad más candente (20)

Pointer Basics,Constant Pointers & Pointer to Constant.
Pointer Basics,Constant Pointers & Pointer to Constant.Pointer Basics,Constant Pointers & Pointer to Constant.
Pointer Basics,Constant Pointers & Pointer to Constant.
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Ch7 C++
Ch7 C++Ch7 C++
Ch7 C++
 
Function in c
Function in cFunction in c
Function in c
 
Learning C++ - Functions in C++ 3
Learning C++ - Functions  in C++ 3Learning C++ - Functions  in C++ 3
Learning C++ - Functions in C++ 3
 
Function in c program
Function in c programFunction in c program
Function in c program
 
functions of C++
functions of C++functions of C++
functions of C++
 
Lecture#6 functions in c++
Lecture#6 functions in c++Lecture#6 functions in c++
Lecture#6 functions in c++
 
Pointers+(2)
Pointers+(2)Pointers+(2)
Pointers+(2)
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
lets play with "c"..!!! :):)
lets play with "c"..!!! :):)lets play with "c"..!!! :):)
lets play with "c"..!!! :):)
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
 
Function overloading(C++)
Function overloading(C++)Function overloading(C++)
Function overloading(C++)
 
C++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIAC++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIA
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Function
FunctionFunction
Function
 
C function
C functionC function
C function
 
Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)
 
FP 201 - Unit 6
FP 201 - Unit 6FP 201 - Unit 6
FP 201 - Unit 6
 
Learn c++ (functions) with nauman ur rehman
Learn  c++ (functions) with nauman ur rehmanLearn  c++ (functions) with nauman ur rehman
Learn c++ (functions) with nauman ur rehman
 

Destacado

Bsc cs ii dfs u-4 sorting and searching structure
Bsc cs ii dfs u-4 sorting and searching structureBsc cs ii dfs u-4 sorting and searching structure
Bsc cs ii dfs u-4 sorting and searching structureRai University
 
Diploma ii cfpc- u-5.3 pointer, structure ,union and intro to file handling
Diploma ii  cfpc- u-5.3 pointer, structure ,union and intro to file handlingDiploma ii  cfpc- u-5.3 pointer, structure ,union and intro to file handling
Diploma ii cfpc- u-5.3 pointer, structure ,union and intro to file handlingRai University
 
Mca ii os u-3 dead lock & io systems
Mca  ii  os u-3 dead lock & io systemsMca  ii  os u-3 dead lock & io systems
Mca ii os u-3 dead lock & io systemsRai University
 
Ob ppt-section-g-f-29-30-aug
Ob ppt-section-g-f-29-30-augOb ppt-section-g-f-29-30-aug
Ob ppt-section-g-f-29-30-augPooja Sakhla
 
Diploma ii cfpc u-4 function, storage class and array and strings
Diploma ii  cfpc u-4 function, storage class and array and stringsDiploma ii  cfpc u-4 function, storage class and array and strings
Diploma ii cfpc u-4 function, storage class and array and stringsRai University
 
Report in al1[1]
Report in al1[1]Report in al1[1]
Report in al1[1]dytpq13
 
Bba ii cam u iv-information systems application & computer security
Bba ii cam  u iv-information systems application & computer securityBba ii cam  u iv-information systems application & computer security
Bba ii cam u iv-information systems application & computer securityRai University
 
Leader member exchange of maguidanaon school heads
Leader member exchange of maguidanaon school headsLeader member exchange of maguidanaon school heads
Leader member exchange of maguidanaon school headsErnie Cerado
 
Correlation testing
Correlation testingCorrelation testing
Correlation testingSteve Bishop
 
Unit 4.2 bba 2 gsi non-performing-assets
Unit 4.2 bba 2 gsi non-performing-assetsUnit 4.2 bba 2 gsi non-performing-assets
Unit 4.2 bba 2 gsi non-performing-assetsRai University
 
B.Sc. Agri II LPM U 4 Disease Control In Livestock
B.Sc. Agri II LPM U 4 Disease Control In LivestockB.Sc. Agri II LPM U 4 Disease Control In Livestock
B.Sc. Agri II LPM U 4 Disease Control In LivestockRai University
 
Mba ewis ii u ii planning and design
Mba ewis ii u ii  planning and designMba ewis ii u ii  planning and design
Mba ewis ii u ii planning and designRai University
 
Mba ii u v e governance
Mba ii u v e governanceMba ii u v e governance
Mba ii u v e governanceRai University
 
Statistical Concepts: Introduction
Statistical Concepts: IntroductionStatistical Concepts: Introduction
Statistical Concepts: IntroductionErnie Cerado
 
Reff 04 macme-installation-tutorial
Reff 04 macme-installation-tutorialReff 04 macme-installation-tutorial
Reff 04 macme-installation-tutorialSalvatore Iaconesi
 

Destacado (20)

Bsc cs ii dfs u-4 sorting and searching structure
Bsc cs ii dfs u-4 sorting and searching structureBsc cs ii dfs u-4 sorting and searching structure
Bsc cs ii dfs u-4 sorting and searching structure
 
Diploma ii cfpc- u-5.3 pointer, structure ,union and intro to file handling
Diploma ii  cfpc- u-5.3 pointer, structure ,union and intro to file handlingDiploma ii  cfpc- u-5.3 pointer, structure ,union and intro to file handling
Diploma ii cfpc- u-5.3 pointer, structure ,union and intro to file handling
 
Mm unit 4point3
Mm unit 4point3Mm unit 4point3
Mm unit 4point3
 
Mca ii os u-3 dead lock & io systems
Mca  ii  os u-3 dead lock & io systemsMca  ii  os u-3 dead lock & io systems
Mca ii os u-3 dead lock & io systems
 
Ob ppt-section-g-f-29-30-aug
Ob ppt-section-g-f-29-30-augOb ppt-section-g-f-29-30-aug
Ob ppt-section-g-f-29-30-aug
 
Diploma ii cfpc u-4 function, storage class and array and strings
Diploma ii  cfpc u-4 function, storage class and array and stringsDiploma ii  cfpc u-4 function, storage class and array and strings
Diploma ii cfpc u-4 function, storage class and array and strings
 
Report in al1[1]
Report in al1[1]Report in al1[1]
Report in al1[1]
 
Bba ii cam u iv-information systems application & computer security
Bba ii cam  u iv-information systems application & computer securityBba ii cam  u iv-information systems application & computer security
Bba ii cam u iv-information systems application & computer security
 
Leader member exchange of maguidanaon school heads
Leader member exchange of maguidanaon school headsLeader member exchange of maguidanaon school heads
Leader member exchange of maguidanaon school heads
 
Mba ii ewis u iv scm
Mba ii ewis u iv scmMba ii ewis u iv scm
Mba ii ewis u iv scm
 
Correlation testing
Correlation testingCorrelation testing
Correlation testing
 
Mba ii ewis u iv erp
Mba ii ewis u iv erpMba ii ewis u iv erp
Mba ii ewis u iv erp
 
Unit 4.2 bba 2 gsi non-performing-assets
Unit 4.2 bba 2 gsi non-performing-assetsUnit 4.2 bba 2 gsi non-performing-assets
Unit 4.2 bba 2 gsi non-performing-assets
 
Approaches to the_analysis_of_survey_data
Approaches to the_analysis_of_survey_dataApproaches to the_analysis_of_survey_data
Approaches to the_analysis_of_survey_data
 
B.Sc. Agri II LPM U 4 Disease Control In Livestock
B.Sc. Agri II LPM U 4 Disease Control In LivestockB.Sc. Agri II LPM U 4 Disease Control In Livestock
B.Sc. Agri II LPM U 4 Disease Control In Livestock
 
Mba ewis ii u ii planning and design
Mba ewis ii u ii  planning and designMba ewis ii u ii  planning and design
Mba ewis ii u ii planning and design
 
If i were 22
If i were 22If i were 22
If i were 22
 
Mba ii u v e governance
Mba ii u v e governanceMba ii u v e governance
Mba ii u v e governance
 
Statistical Concepts: Introduction
Statistical Concepts: IntroductionStatistical Concepts: Introduction
Statistical Concepts: Introduction
 
Reff 04 macme-installation-tutorial
Reff 04 macme-installation-tutorialReff 04 macme-installation-tutorial
Reff 04 macme-installation-tutorial
 

Similar a Files, Pointers, I/O Streams in C++ Explained

C++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptxC++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptxShashiShash2
 
18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operator18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operatorSAFFI Ud Din Ahmad
 
1. DSA - Introduction.pptx
1. DSA - Introduction.pptx1. DSA - Introduction.pptx
1. DSA - Introduction.pptxhara69
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloadingankush_kumar
 
2.overview of c++ ________lecture2
2.overview of c++  ________lecture22.overview of c++  ________lecture2
2.overview of c++ ________lecture2Warui Maina
 
chapter-7 slide.pptx
chapter-7 slide.pptxchapter-7 slide.pptx
chapter-7 slide.pptxcricketreview
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1AmIt Prasad
 
presentation_pointers_1444076066_140676 (1).ppt
presentation_pointers_1444076066_140676 (1).pptpresentation_pointers_1444076066_140676 (1).ppt
presentation_pointers_1444076066_140676 (1).pptgeorgejustymirobi1
 
C++ Pointers with Examples.docx
C++ Pointers with Examples.docxC++ Pointers with Examples.docx
C++ Pointers with Examples.docxJoeyDelaCruz22
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming FundamentalsZohaib Sharif
 
Function in c program
Function in c programFunction in c program
Function in c programumesh patil
 
FUNCTIONS, CLASSES AND OBJECTS.pptx
FUNCTIONS, CLASSES AND OBJECTS.pptxFUNCTIONS, CLASSES AND OBJECTS.pptx
FUNCTIONS, CLASSES AND OBJECTS.pptxDeepasCSE
 

Similar a Files, Pointers, I/O Streams in C++ Explained (20)

C++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptxC++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptx
 
C++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptxC++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptx
 
18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operator18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operator
 
1. DSA - Introduction.pptx
1. DSA - Introduction.pptx1. DSA - Introduction.pptx
1. DSA - Introduction.pptx
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloading
 
2.overview of c++ ________lecture2
2.overview of c++  ________lecture22.overview of c++  ________lecture2
2.overview of c++ ________lecture2
 
chapter-7 slide.pptx
chapter-7 slide.pptxchapter-7 slide.pptx
chapter-7 slide.pptx
 
pointers.pptx
pointers.pptxpointers.pptx
pointers.pptx
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
 
presentation_pointers_1444076066_140676 (1).ppt
presentation_pointers_1444076066_140676 (1).pptpresentation_pointers_1444076066_140676 (1).ppt
presentation_pointers_1444076066_140676 (1).ppt
 
c program.ppt
c program.pptc program.ppt
c program.ppt
 
Unit 6 pointers
Unit 6   pointersUnit 6   pointers
Unit 6 pointers
 
C++ Pointers with Examples.docx
C++ Pointers with Examples.docxC++ Pointers with Examples.docx
C++ Pointers with Examples.docx
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Function in c program
Function in c programFunction in c program
Function in c program
 
FUNCTIONS, CLASSES AND OBJECTS.pptx
FUNCTIONS, CLASSES AND OBJECTS.pptxFUNCTIONS, CLASSES AND OBJECTS.pptx
FUNCTIONS, CLASSES AND OBJECTS.pptx
 
Array Cont
Array ContArray Cont
Array Cont
 
C++ Functions.ppt
C++ Functions.pptC++ Functions.ppt
C++ Functions.ppt
 

Más de Rai University

Brochure Rai University
Brochure Rai University Brochure Rai University
Brochure Rai University Rai University
 
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,Rai University
 
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02Rai University
 
Bsc agri 2 pae u-4.3 public expenditure
Bsc agri  2 pae  u-4.3 public expenditureBsc agri  2 pae  u-4.3 public expenditure
Bsc agri 2 pae u-4.3 public expenditureRai University
 
Bsc agri 2 pae u-4.2 public finance
Bsc agri  2 pae  u-4.2 public financeBsc agri  2 pae  u-4.2 public finance
Bsc agri 2 pae u-4.2 public financeRai University
 
Bsc agri 2 pae u-4.1 introduction
Bsc agri  2 pae  u-4.1 introductionBsc agri  2 pae  u-4.1 introduction
Bsc agri 2 pae u-4.1 introductionRai University
 
Bsc agri 2 pae u-3.3 inflation
Bsc agri  2 pae  u-3.3  inflationBsc agri  2 pae  u-3.3  inflation
Bsc agri 2 pae u-3.3 inflationRai University
 
Bsc agri 2 pae u-3.2 introduction to macro economics
Bsc agri  2 pae  u-3.2 introduction to macro economicsBsc agri  2 pae  u-3.2 introduction to macro economics
Bsc agri 2 pae u-3.2 introduction to macro economicsRai University
 
Bsc agri 2 pae u-3.1 marketstructure
Bsc agri  2 pae  u-3.1 marketstructureBsc agri  2 pae  u-3.1 marketstructure
Bsc agri 2 pae u-3.1 marketstructureRai University
 
Bsc agri 2 pae u-3 perfect-competition
Bsc agri  2 pae  u-3 perfect-competitionBsc agri  2 pae  u-3 perfect-competition
Bsc agri 2 pae u-3 perfect-competitionRai University
 

Más de Rai University (20)

Brochure Rai University
Brochure Rai University Brochure Rai University
Brochure Rai University
 
Mm unit 4point2
Mm unit 4point2Mm unit 4point2
Mm unit 4point2
 
Mm unit 4point1
Mm unit 4point1Mm unit 4point1
Mm unit 4point1
 
Mm unit 4point3
Mm unit 4point3Mm unit 4point3
Mm unit 4point3
 
Mm unit 3point2
Mm unit 3point2Mm unit 3point2
Mm unit 3point2
 
Mm unit 3point1
Mm unit 3point1Mm unit 3point1
Mm unit 3point1
 
Mm unit 2point2
Mm unit 2point2Mm unit 2point2
Mm unit 2point2
 
Mm unit 2 point 1
Mm unit 2 point 1Mm unit 2 point 1
Mm unit 2 point 1
 
Mm unit 1point3
Mm unit 1point3Mm unit 1point3
Mm unit 1point3
 
Mm unit 1point2
Mm unit 1point2Mm unit 1point2
Mm unit 1point2
 
Mm unit 1point1
Mm unit 1point1Mm unit 1point1
Mm unit 1point1
 
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
 
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
 
Bsc agri 2 pae u-4.3 public expenditure
Bsc agri  2 pae  u-4.3 public expenditureBsc agri  2 pae  u-4.3 public expenditure
Bsc agri 2 pae u-4.3 public expenditure
 
Bsc agri 2 pae u-4.2 public finance
Bsc agri  2 pae  u-4.2 public financeBsc agri  2 pae  u-4.2 public finance
Bsc agri 2 pae u-4.2 public finance
 
Bsc agri 2 pae u-4.1 introduction
Bsc agri  2 pae  u-4.1 introductionBsc agri  2 pae  u-4.1 introduction
Bsc agri 2 pae u-4.1 introduction
 
Bsc agri 2 pae u-3.3 inflation
Bsc agri  2 pae  u-3.3  inflationBsc agri  2 pae  u-3.3  inflation
Bsc agri 2 pae u-3.3 inflation
 
Bsc agri 2 pae u-3.2 introduction to macro economics
Bsc agri  2 pae  u-3.2 introduction to macro economicsBsc agri  2 pae  u-3.2 introduction to macro economics
Bsc agri 2 pae u-3.2 introduction to macro economics
 
Bsc agri 2 pae u-3.1 marketstructure
Bsc agri  2 pae  u-3.1 marketstructureBsc agri  2 pae  u-3.1 marketstructure
Bsc agri 2 pae u-3.1 marketstructure
 
Bsc agri 2 pae u-3 perfect-competition
Bsc agri  2 pae  u-3 perfect-competitionBsc agri  2 pae  u-3 perfect-competition
Bsc agri 2 pae u-3 perfect-competition
 

Último

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 

Último (20)

TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 

Files, Pointers, I/O Streams in C++ Explained

  • 2. Basic Input /Output stream description cin standard input stream cout standard output stream cerr standard error (output) stream clog standard logging(output) stream
  • 3. Standard output (cout) cout << "Output sentence"; // prints Output sentence on screen cout << 120; // prints number 120 on screen cout << x; // prints the value of x on screen cout << "Hello"; // prints Hello cout << Hello; // prints the content of variable Hello
  • 4. Standard input (cin) int age; cin >> age; i/o example : #include <iostream> using namespace std; int main () { int i; cout << "Please enter an integer value: "; cin >> i;
  • 5. Standard input (cin) cout << "The value you entered is " << i; cout << " and its double is " << i*2 << ".n";return0; } O/P:- Please enter an integer value: 702 The value you entered is 702 and its double is 1404.
  • 6. Read/write modes in C++. Reading A File #include <fstream.h> void main() { ifstream OpenFile("cpp-home.txt"); char ch; while(!OpenFile.eof()) { OpenFile.get(ch); cout << ch; } OpenFile.close(); }
  • 7. Read/write modes in C++. Writing A File #include <stdio.h> #include <string.h> int main(int argc, char * argv[]) { const char * filename="test.txt"; const char * mytext="Once upon a time there were three bears."; int byteswritten=0; FILE * ft= fopen(filename, "wb") ;
  • 8. Read/write modes in C++.   if (ft)  {     fwrite(mytext,sizeof(char),strlen(mytext), ft) ;    fclose( ft ) ;    }  printf("len of mytext = %i ",strlen(mytext)) ;    return 0;  } 
  • 10. Reference and dereference operators  In the example above we used ampersand sign (&).  This sign is called the reference operator.   If  the  reference  operator  is  used  you  will  get  the  “address of” a variable.   In the example  we said: ptr_p = &x;. In words: store  the address of the variable x in the pointer ptr_p.
  • 11. Reference and dereference operators  We  also  used  the  asterisk  sign  (*)  in  the  cout  statement.  This  sign  is  called  the  dereference  operator.   If  the  dereference  operator  is  used  you  will  get  the  “value pointed by” a pointer.   So cout << *ptr_p;. In words: print (or put into the  stream) the value pointed by ptr_p. (It will print the  contents of integer x.)
  • 13. Reference and dereference operators The  address  of  a  variable  can  be  obtained  by  preceding the name of a variable with an ampersand  sign (&), known as reference operator, and which can  be  literally  translated  as  "address  of".  foo = &myvar; myvar = 25; foo = &myvar;  bar = myvar;
  • 14. Reference operator 1.First,  we  have  assigned  the  value 25 to myvar (a  variable  whose  address  in  memory  we  assumed  to  be 1776). 2.The  second  statement  assigns foo the  address    of myvar,  which  we  have  assumed  to  be 1776. 3.Finally,  the  third  statement,  assigns  the  value  contained  in myvar to bar.  This  is  a  standard  assignment operation, as already done many times in  earlier.  .
  • 15. Reference operator 4.The main difference between the second and third statements is the appearance of the reference operator (&). 5.The variable that stores the address of another variable (like foo in the previous example) is what in C++ is called a pointer.
  • 16. Dereference operators  An interesting property of pointers is that they can be used to access the variable they point to directly. This is done by preceding the pointer name with the dereference operator (*). The operator itself can be read as "value pointed toby”. baz = *foo;  This could be read as: "baz equal to value pointed to by foo", and the statement would actually assign the value25 to baz, since foo is 1776, and the value pointed to by 1776 (following the example above) would be 25.
  • 18. Dereference operators  It is important to clearly differentiate that foo refers to the value 1776, while *foo (with an asterisk * preceding the identifier) refers to the value stored at address 1776, which in this case is 25.  Notice the difference of including or not including the dereference operator (I have added an explanatory comment of how each of these two expressions could be read):
  • 19. Dereference operators  & is the reference operator, and can be read as "address of“  * is the dereference operator, and can be read as "value pointed to by" •
  • 20. Passing Pointer to functions,  To call the function pointed to by a function pointer, you treat the function pointer as though it were the name of the function you wish to call.  The act of calling it performs the dereference; there's no need to do it yourself:
  • 21. Passing Pointer to functions, #include <stdio.h> void my_int_func(int x) { printf( "%dn", x ); } int main() { void (*foo)(int); foo = &my_int_func; foo( 2 ); (*foo)( 2 ); return 0; }
  • 22. Pointer to Arrays #include <iostream> using namespace std; const int MAX = 3; int main () { int var[MAX] = {10, 100, 200}; int *ptr[MAX]; for (int i = 0; i < MAX; i++) {
  • 23. Pointer to Arrays ptr[i] = &var[i]; } for (int i = 0; i < MAX; i++) { cout << "Value of var[" << i << "] = "; cout << *ptr[i] << endl; }return0; }
  • 24. Pointer to Arrays OUTPUT: Value of var[0] = 10 Value of var[1] = 100 Value of var[2] = 200
  • 25. REFRENCES • Learn Programming in C++ By Anshuman Sharma, Anurag Gupta, Dr.Hardeep Singh, Vikram Sharma