The document discusses pointers in C++. It defines a pointer as a special variable that stores the address of another variable of the same data type. It provides examples of declaring and accessing pointers, pointer arithmetic, pointers as function parameters and return types, pointers and arrays, pointers and strings, and pointers and structures. Key topics covered include pointer operators & and *, pointer arithmetic, self-referential structures, and an example of a linked list using pointers and nodes.
Create the equivalent of a four function calculator. The program should request the user to enter a number, an operator, and another number. carry out the specified arithmetical operation: adding, subtracting, multiplying, or dividing the two numbers. (Using switch statement ).ThesisScientist.com
Create the equivalent of a four function calculator. The program should request the user to enter a number, an operator, and another number. carry out the specified arithmetical operation: adding, subtracting, multiplying, or dividing the two numbers. (Using switch statement ).ThesisScientist.com
A class that automates conversion from a C++ recursive function to an iterative function. It allow the recursive function to preserve its structure by reproducing the "call stack" on an std::stack. The examples use combinatorics to illustrate usage.
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...Kevlin Henney
Presented at ACCU (24th April 2015)
It is all to easy to dismiss problematic codebases on some nebulous idea of bad practice or bad programmers. Poor code, however, is rarely arbitrary and random in its structure or formulation. Systems of code, well or poorly structured, emerge from systems of practice, whether effective or ineffective. To improve code quality, it makes more sense to pick apart the specific practices and see their interplay — the cause — than to simply focus on the code itself — the effect. This talk looks at how a handful of coding habits, design practices and assumptions can systematically balloon code and compound its accidental complexity.
In this talk, Adrian Kashivskyy, Netguru iOS Developer, digs into rarely discussed Swift features, such as literal convertibles, interpolation convertibles, pattern matching, reflection and advanced Objective-C bridging.
A class that automates conversion from a C++ recursive function to an iterative function. It allow the recursive function to preserve its structure by reproducing the "call stack" on an std::stack. The examples use combinatorics to illustrate usage.
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...Kevlin Henney
Presented at ACCU (24th April 2015)
It is all to easy to dismiss problematic codebases on some nebulous idea of bad practice or bad programmers. Poor code, however, is rarely arbitrary and random in its structure or formulation. Systems of code, well or poorly structured, emerge from systems of practice, whether effective or ineffective. To improve code quality, it makes more sense to pick apart the specific practices and see their interplay — the cause — than to simply focus on the code itself — the effect. This talk looks at how a handful of coding habits, design practices and assumptions can systematically balloon code and compound its accidental complexity.
In this talk, Adrian Kashivskyy, Netguru iOS Developer, digs into rarely discussed Swift features, such as literal convertibles, interpolation convertibles, pattern matching, reflection and advanced Objective-C bridging.
CONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptxDeepasCSE
Certainly, here's a brief explanation of constructors, destructors, and operator overloading without using code:
Constructors: Constructors are special methods used to initialize objects of a class. They set the initial state of an object when it is created.
Destructors: Destructors are special methods used to clean up resources and perform necessary cleanup when an object is no longer needed or goes out of scope. They ensure proper resource management.
Operator Overloading: Operator overloading is a feature that allows you to define custom behaviors for operators such as +, -, *, /, etc., when they are applied to objects of your class. It enables you to work with objects in a way that is meaningful for your specific class.
Constructors can be of different types:
Default Constructors: Initialize objects with default values.
Parameterized Constructors: Accept arguments to initialize objects with specific values.
Copy Constructors: Create a new object as a copy of an existing object.
Constructor Overloading: A class can have multiple constructors with different parameter lists, providing flexibility in object initialization.
Destructors are executed automatically when an object is destroyed. They are essential for releasing resources like memory, file handles, or network connections, ensuring proper cleanup and preventing resource leaks.
Operator overloading enables you to define how operators work with objects of your class. For instance, you can specify what the + operator does when applied to two objects of your class, allowing for custom operations that make sense in the context of your class's functionality.
In summary, constructors initialize objects, destructors handle cleanup, and operator overloading allows custom operations with operators when working with objects. These features are crucial for building custom classes in object-oriented programming.
Functions, classes, and objects are fundamental concepts in object-oriented programming. Here's a brief explanation of each:
Functions:
Functions are blocks of code that perform specific tasks or computations.
They encapsulate a set of instructions and can take parameters (input) and return values (output).
Functions are reusable, promoting code modularity and maintainability.
Classes:
Classes are blueprints or templates for creating objects.
They define the structure and behavior of objects by specifying attributes (data members) and methods (functions) that the objects will have.
Classes serve as a model for creating multiple instances (objects) with similar characteristics.
Objects:
Objects are instances of classes.
They are concrete representations of the class's blueprint, with their own unique data values and the ability to perform actions using the methods defined in the class.
Objects are used to model and manipulate real-world entities in code.
In summary, functions are used to define specific tasks or operations, classes serve as templates for creating objects with shared attributes and behaviors, and objects are instances of classes that represent real-world entities and can interact with their environment. These concepts are central to object-oriented programming and software development.
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Dr. Vinod Kumar Kanvaria
Exploiting Artificial Intelligence for Empowering Researchers and Faculty,
International FDP on Fundamentals of Research in Social Sciences
at Integral University, Lucknow, 06.06.2024
By Dr. Vinod Kumar Kanvaria
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Francesca Gottschalk - How can education support child empowerment.pptxEduSkills OECD
Francesca Gottschalk from the OECD’s Centre for Educational Research and Innovation presents at the Ask an Expert Webinar: How can education support child empowerment?
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
Digital Tools and AI for Teaching Learning and Research
P1
1. Prepared By : Rakesh Kumar D.A.V.Centenary Public School Chander Nagar
Pointer in C++
Pointer is a special variable, used to store the address of another variable of same data type.
#include<iostream>
#include<conio.h> a
using namespace std;
int main() 5
{
int a; 10234
a=5;
cout<<"n Value of a :"<<a; // 5 is the value stored at a
cout<<"n Address of a :"<<&a; // 10234 is the address of variable a
getch( );
return 0;
}
& :- is known as address operator
* :- is known as value operator if it is operative on address, otherwise it behaves like a multiplication
operator
Arithmetic Operation on Pointer : Only allowed arithmetic operation is addition(+) and Subtraction(-)
Program Output
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int a;
a=5;
int *b;
b=&a;
cout<<"n Value of b :"<<b<<endl;
b=b+1 ; // increase block size
cout<<"n New value of b :"<<b<<endl;
getch();
return 0;
}
Pointer of Pointer
Program Output
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int a;
a=5;
int *b;
b=&a;
int **c;
c=&b;
int ***d;
d=&c;
cout<<"n Address of ann";
cout<<"n Using &a :"<<&a;
cout<<"n Using b :"<<b;
cout<<"n Using *c :"<<*c;
cout<<"n Using **d :"<<**d;
cout<<"nnn Value of an";
cout<<"n Using a :"<<a;
Page 1 of 11
2. Prepared By : Rakesh Kumar D.A.V.Centenary Public School Chander Nagar
cout<<"n Using *(&a) :"<<*(&a);
cout<<"n Using *b :"<<*b;
cout<<"n Using **c :"<<**c;
cout<<"n Using ***d :"<<***d;
getch();
return 0;
}
Pointer as a function parameter
Program Output
// program to demonstrate call by pointer method
#include<iostream>
#include<conio.h>
using namespace std;
void change(int *a) // parameter as pointer
{
*a = *a+20;
}
int main()
{
int x=20;
cout<<"n Value of x before function call:"<<x;
change(&x); // passing parameter
cout<<"n Value of x before function call:"<<x;
getch();
return 0;
}
Pointer as a function Return type value
Program Output
#include<iostream>
#include<conio.h>
using namespace std;
int* read(void)
{
int a;
a=20;
return(&a);
}
int main()
{
int *res;
res = read(); // store retured address
cout<<"n Value of a :"<<*res;
cout<<"n Value of a :"<<*(read());
getch();
return 0;
}
Pointer and Array
When an array is defined like
int x[5]; // The memory block is as shown below
X
100 102 104 106 108
The address of 0th index block is called BASE ADDRESS and it can be obtained by the following
methods
Page 2 of 11
3. Prepared By : Rakesh Kumar D.A.V.Centenary Public School Chander Nagar
(a) x -> 100
(b) &x[0] ->100
(c) x+0 ->100
(d) 0+x ->100
(e) &0[x] ->100
Processing array as a pointer without using any extra pointer variable
Program Output
// program to access array as
a pointer
#include<iostream>
#include<iomanip>
#include<conio.h>
#include<math.h>
using namespace std;
int main()
{
int x[10],i;
// input phase
for(i=0;i<10;i++)
{
cout<<"Enter value :";
cin>>x[i];
}
// output
cout<<"n Output using as
a pointer:n";
for(i=0;i<10;i++)
cout<<setw(6)<<*(x+i);
getch();
return 0;
}
Processing array as a pointer using extra pointer variable
Program Output
#include<iostream>
#include<iomanip>
#include<conio.h>
#include<math.h>
using namespace std;
int main()
{
int x[10],i,*p;
p= x; // assign base
address to p
// input phase
for(i=0;i<10;i++)
x[i]=rand();
// output
for(i=0;i<10;i++)
{
cout<<setw(6)<<*p;
p++;
}
getch();
return 0;
}
Page 3 of 11
4. Prepared By : Rakesh Kumar D.A.V.Centenary Public School Chander Nagar
Accessing pointer as an array
Program Output
#include<iostream>
#include<iomanip>
#include<conio.h>
#include<math.h>
using namespace std;
void change(int *x)
{
int i;
for(i=0;i<10;i++)
x[i]=x[i]+20;
}
int main()
{
int x[10],i;
// input phase
for(i=0;i<10;i++)
{
cout<<"Enter value :";
cin>>x[i];
}
// processing phase
change(x);
// output phase
cout<<"n Modified List :";
for(i=0;i<10;i++)
cout<<setw(6)<<x[i];
getch();
return 0;
}
Pointer & String
String : it is an array of character, which always terminates with NULL (‘0’).
Char str[80]=”RAKESH”; // It’s allocation in stin is as follows
0 1 2 3 4 5 6 7 8 9 ……………………………………………………..79
R A K E S H 0
101 102 103 104 105………………………………………………………………………… ………180
cout<<str; // Please note that only the base address of string has been given to cout
// and cout is here print the whole string not the base address
Result : RAKESH
Example 2.
char str[80]=”RAKESH”;
cout<<*str; // now compiler try to print value stored at base address
Result : ‘R’
Example 3
char str[80]=”RAKESH”;
cout<<*++str; // process nearest first
Result : ‘A’
Page 4 of 11
5. Prepared By : Rakesh Kumar D.A.V.Centenary Public School Chander Nagar
Example 4
char str[80]=”RAKESH”;
cout<<++*str; // process nearest first
Result : ‘S’
Example 5
char str[80]=”RAKESH”;
cout<<++str; // print 101 address onward upto NULL
Result : AKESH
Pointers and Structure
Assigning and Accesssing structure type Pointers
#include<iostream>
#include<conio.h>
using namespace std;
struct student
{
int roll;
char name[30];
char address[60];
};
int main()
{
student s;
student *s1;
s1= &s;
//input phase
cout<<"n Enter roll no :";
cin>>s.roll;
cout<<"n Enter name :";
cin>>s.name;
cout<<"n Enter address :";
cin>>s.address;
// output - using pointer variable
cout<<"n Roll :"<<(*s1).roll; // s1->roll
cout<<"n Nane :"<<(*s1).name; // s1->name;
cout<<"n Address :"<<(*s1).address; // s1->address
getch();
return 0;
}
Page 5 of 11
6. Prepared By : Rakesh Kumar D.A.V.Centenary Public School Chander Nagar
New ( ) : This function is used to assign memory to a pointer variable from the available memory heap. The
function is responsible to calculate no of bytes and types of data, required.
Delete ( ) : This function is used to release assigned pointer memory to memory heap
Accessing Pointer Variable using new( ) and delete ( ) function
#include<iostream>
#include<conio.h>
using namespace std;
struct student
{
int roll;
char name[30];
char address[60];
};
int main()
{
student *s;
s= new(student);
//input phase
cout<<"n Enter roll no :";
cin>>s->roll;
cout<<"n Enter name :";
cin>>s->name;
cout<<"n Enter address :";
cin>>s->address;
// output - using pointer variable
cout<<"n Roll :"<<s->roll;
cout<<"n Name :"<<s->name;
cout<<"n Address :"<<s->address;
delete(s);
getch();
return 0; }
Self Referential Structure: A structure which can have a variable of it’s own type inside it’s declaration,
then the structure is known as self referential structure.
Example
struct student
{
Int roll;
` student *s;
};
Example of link list
#include<iostream>
#include<iomanip>
#include<conio.h>
using namespace std;
struct node
{
int info;
node *ptr;
};
int main()
{
node *x,*y,*temp ;
x= NULL;
int choice;
do
{
system("cls");
cout<<"n 1. Add at beginning";
Page 6 of 11
7. Prepared By : Rakesh Kumar D.A.V.Centenary Public School Chander Nagar
cout<<"n 2. Add at end";
cout<<"n 3. Delete from beginning";
cout<<"n 4. Display ";
cout<<"n 5. Exit";
cout<<"nnn Enter your choice :";
cin>>choice;
switch(choice)
{
case 1: if(x==NULL)
{
x = new(node);
cout<<"n Enter value :";
cin>>x->info;
x->ptr = NULL;
}
else
{
temp = new(node);
cout<<"n Enter value :";
cin>>temp->info;
temp->ptr = x;
x = temp;
}
break;
case 2: if(x==NULL)
{
x = new(node);
cout<<"n Enter value :";
cin>>x->info;
x->ptr = NULL;
}
else
{
y =x;
while(y->ptr!=NULL)
y = y->ptr;
y->ptr = new(node);
y = y->ptr;
cout<<"n Enter value :";
cin>>y->info;
y->ptr = NULL;
}
break;
case 3:
if(x==NULL)
{
cout<<"n Link List empty";
getch();
}
else
{
temp =x;
x = x->ptr;
delete(temp);
}
break;
case 4:
if(x==NULL)
cout<<"n Link list empty";
else
{
y = x;
while(y!=NULL)
{
cout<<setw(6)<<y->info;
y = y->ptr;
Page 7 of 11
8. Prepared By : Rakesh Kumar D.A.V.Centenary Public School Chander Nagar
}
}
getch();
break;
case 5: break;
default:
cout<<"n Wrong Choice.... Try again";
getch();
} // end of switch statement
}while(choice!=5);
return 0;
}
LINK LIST EMPLEMENTED STACK
#include<iostream>
#include<iomanip>
#include<conio.h>
using namespace std;
struct node
{
int info;
node *ptr;
};
class stack
{
node *x,*y,*temp;
public:
stack() // constructor to initialize variable
{
x= NULL;
}
void push(void); // function to add element
void pop(void); // function to delete element
void display(void); // function to display stack element
};
void stack::push()
{
if(x==NULL)
{
x = new(node);
cout<<"n Enter value :";
cin>>x->info;
x->ptr = NULL;
}
else
{
temp = new(node);
cout<<"n Enter value :";
cin>>temp->info;
temp->ptr = x;
x = temp;
}
return;
}
void stack::pop(void)
{
if(x==NULL)
{
cout<<"n Stack is empty";
getch();
}
else
Page 8 of 11
9. Prepared By : Rakesh Kumar D.A.V.Centenary Public School Chander Nagar
{
temp =x;
x = x->ptr;
delete(temp);
}
return;
}
void stack::display()
{
if(x==NULL)
cout<<"n Link list empty";
else
{
y = x;
while(y!=NULL)
{
cout<<setw(6)<<y->info;
y = y->ptr;
}
}
return;
}
int main()
{
stack S;
int choice;
do
{
system("cls");
cout<<"n S T A C K M E N U ";
cout<<"n 1. Push";
cout<<"n 2. Pop";
cout<<"n 3. Display ";
cout<<"n 4. Exit";
cout<<"nnn Enter your choice :";
cin>>choice;
switch(choice)
{
case 1: S.push();
break;
case 2: S.pop();
break;
case 3: S.display();
getch();
break;
case 4: break;
default:
cout<<"n Wrong Choice.... Try again";
getch();
}
}while(choice!=4);
return 0;
}
Link List Implemented queue
#include<iostream>
#include<iomanip>
#include<conio.h>
using namespace std;
struct node
{
Page 9 of 11
10. Prepared By : Rakesh Kumar D.A.V.Centenary Public School Chander Nagar
int info;
node *ptr;
};
class queue
{
node *x,*y,*temp;
public:
queue() // constructor to initliaze variable
{
x= NULL;
}
void add_element(void); // function to add element
void delete_element(void); // function to delete element
void display(void); // function to display stack element
};
void queue::add_element()
{
if(x==NULL)
{
x = new(node);
cout<<"n Enter value :";
cin>>x->info;
x->ptr = NULL;
}
else
{
y = x;
while(y->ptr!=NULL)
y = y->ptr;
y->ptr = new(node);
y = y->ptr;
cout<<"n Enter value :";
cin>>y->info;
y->ptr = NULL;
}
return;
}
void queue::delete_element(void)
{
if(x==NULL)
{
cout<<"n queue is empty";
getch();
}
else
{
temp =x;
x = x->ptr;
delete(temp);
}
return;
}
void queue::display()
{
if(x==NULL)
cout<<"n Queue is empty";
else
{
y = x;
while(y!=NULL)
{
cout<<setw(6)<<y->info;
y = y->ptr;
Page 10 of 11
11. Prepared By : Rakesh Kumar D.A.V.Centenary Public School Chander Nagar
}
}
return;
}
int main()
{
queue q;
int choice;
do
{
system("cls");
cout<<"n QUEUE M E N U ";
cout<<"n 1. Add Element";
cout<<"n 2. Delete Element";
cout<<"n 3. Display ";
cout<<"n 4. Exit";
cout<<"nnn Enter your choice :";
cin>>choice;
switch(choice)
{
case 1: q.add_element();
break;
case 2: q.delete_element();
break;
case 3: q.display();
getch();
break;
case 4:
break;
default:
cout<<"n Wrong Choice.... Try again";
getch();
}
}while(choice!=4);
return 0;
}
Page 11 of 11