This document discusses pointers in C++. It begins by defining pointers as variables that hold the memory addresses of other variables and explaining that pointers have types corresponding to the types of variables they point to. It then covers initializing and dereferencing pointers, constant pointers, pointer arithmetic, pointers and arrays, using pointers as function arguments, and memory management using pointers with the new and delete operators.
A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before you can use it to store any variable address.
There are few important operations, which we will do with the help of pointers very frequently. (a) we define a pointer variable (b) assign the address of a variable to a pointer and (c) finally access the value at the address available in the pointer variable. This is done by using unary operator * that returns the value of the variable located at the address specified by its operand.
A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before you can use it to store any variable address.
There are few important operations, which we will do with the help of pointers very frequently. (a) we define a pointer variable (b) assign the address of a variable to a pointer and (c) finally access the value at the address available in the pointer variable. This is done by using unary operator * that returns the value of the variable located at the address specified by its operand.
This Presentation gives you all knowledge about #CPointers, #PointersInC.
The given slides are as follows:
1. Introduction of Pointers.
2. Systems to create a pointer in C.
3. Valid Pointer Examples in C.
4. Graphical representation of address assigning in c using pointer.
5. 1st Sample program of pointers in C.
6. Types of Pointers
7. NULL Pointer in C (Types of Pointer)
8. void Pointer in C (Types of Pointer)
9. Wild Pointer in C (Types of Pointer)
10. Changing value of variable using pointer
11. Update and Access value of variable using pointer in example.
12. Types of format specifies to print address in different format.
13. Advantages of Pointer in C.
14. Disadvantages of Pointer in C.
15. Pointers with Array using Programs. #pointerwitharray
16. Another Example of #pointerwitharray.
17. Relationship Between Arrays and Pointers.
18. Relationship Between Arrays and Pointers explanation with diagram.
19. Pointers and String. #PointersAndString
20. Function with Array Parameters using pointers.
21. Passing Pointers to Function or Pointer argument function. #PointerWithFunction
In computer science, a pointer is a programming language object, whose value refers to (or "points to") another value stored elsewhere in the computer memory using its memory address. A pointer references a location in memory, and obtaining the value stored at that location is known as dereferencing the pointer.
An introduction to pointers and references in C++ (with elements of C++11 and C++14). The presentation introduces the readers to the concepts of pointers and references through the pragmatic need of writing a swap function between integers. Generic programming notions (e.g., type constructors) are adopted when useful for the explanation.
Pointers are among C’s most powerful, yet most difficult concepts to master. Some tasks like dynamic memory allocation done only by using pointers. So it is essential to learn pointers.
Pointers are a type of variable, just like int, double, etc., except instead of storing a value, they store a memory address of another variable.
This Presentation gives you all knowledge about #CPointers, #PointersInC.
The given slides are as follows:
1. Introduction of Pointers.
2. Systems to create a pointer in C.
3. Valid Pointer Examples in C.
4. Graphical representation of address assigning in c using pointer.
5. 1st Sample program of pointers in C.
6. Types of Pointers
7. NULL Pointer in C (Types of Pointer)
8. void Pointer in C (Types of Pointer)
9. Wild Pointer in C (Types of Pointer)
10. Changing value of variable using pointer
11. Update and Access value of variable using pointer in example.
12. Types of format specifies to print address in different format.
13. Advantages of Pointer in C.
14. Disadvantages of Pointer in C.
15. Pointers with Array using Programs. #pointerwitharray
16. Another Example of #pointerwitharray.
17. Relationship Between Arrays and Pointers.
18. Relationship Between Arrays and Pointers explanation with diagram.
19. Pointers and String. #PointersAndString
20. Function with Array Parameters using pointers.
21. Passing Pointers to Function or Pointer argument function. #PointerWithFunction
In computer science, a pointer is a programming language object, whose value refers to (or "points to") another value stored elsewhere in the computer memory using its memory address. A pointer references a location in memory, and obtaining the value stored at that location is known as dereferencing the pointer.
An introduction to pointers and references in C++ (with elements of C++11 and C++14). The presentation introduces the readers to the concepts of pointers and references through the pragmatic need of writing a swap function between integers. Generic programming notions (e.g., type constructors) are adopted when useful for the explanation.
Pointers are among C’s most powerful, yet most difficult concepts to master. Some tasks like dynamic memory allocation done only by using pointers. So it is essential to learn pointers.
Pointers are a type of variable, just like int, double, etc., except instead of storing a value, they store a memory address of another variable.
COURSE TITLE: SOFTWARE DEVELOPMENT VI
COURSE CODE: VIT 351
TOPICS COVERED:
INTRODUCTION TO POINTERS
TYPES OF POINTERS
POINTERS EXAMPLES
POINTERS ARITHMETICS
ADVANTAGES AND DISADVANTAGES OF POINTERS
STATIC MEMORY ALLOCATION
DYNAMIC MEMORY ALLOCATION
QUIZ SET 3
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
DevOps and Testing slides at DASA ConnectKari Kakkonen
My and Rik Marselis slides at 30.5.2024 DASA Connect conference. We discuss about what is testing, then what is agile testing and finally what is Testing in DevOps. Finally we had lovely workshop with the participants trying to find out different ways to think about quality and testing in different parts of the DevOps infinity loop.
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
A presentation about the usage and availability of Varnish on Kubernetes. This talk explores the capabilities of Varnish caching and shows how to use the Varnish Helm chart to deploy it to Kubernetes.
This presentation was delivered at K8SUG Singapore. See https://feryn.eu/presentations/accelerate-your-kubernetes-clusters-with-varnish-caching-k8sug-singapore-28-2024 for more details.
Neuro-symbolic is not enough, we need neuro-*semantic*Frank van Harmelen
Neuro-symbolic (NeSy) AI is on the rise. However, simply machine learning on just any symbolic structure is not sufficient to really harvest the gains of NeSy. These will only be gained when the symbolic structures have an actual semantics. I give an operational definition of semantics as “predictable inference”.
All of this illustrated with link prediction over knowledge graphs, but the argument is general.
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
Generating a custom Ruby SDK for your web service or Rails API using Smithyg2nightmarescribd
Have you ever wanted a Ruby client API to communicate with your web service? Smithy is a protocol-agnostic language for defining services and SDKs. Smithy Ruby is an implementation of Smithy that generates a Ruby SDK using a Smithy model. In this talk, we will explore Smithy and Smithy Ruby to learn how to generate custom feature-rich SDKs that can communicate with any web service, such as a Rails JSON API.
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
Keynote at DIGIT West Expo, Glasgow on 29 May 2024.
Cheryl Hung, ochery.com
Sr Director, Infrastructure Ecosystem, Arm.
The key trends across hardware, cloud and open-source; exploring how these areas are likely to mature and develop over the short and long-term, and then considering how organisations can position themselves to adapt and thrive.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
JMeter webinar - integration with InfluxDB and GrafanaRTTS
Watch this recorded webinar about real-time monitoring of application performance. See how to integrate Apache JMeter, the open-source leader in performance testing, with InfluxDB, the open-source time-series database, and Grafana, the open-source analytics and visualization application.
In this webinar, we will review the benefits of leveraging InfluxDB and Grafana when executing load tests and demonstrate how these tools are used to visualize performance metrics.
Length: 30 minutes
Session Overview
-------------------------------------------
During this webinar, we will cover the following topics while demonstrating the integrations of JMeter, InfluxDB and Grafana:
- What out-of-the-box solutions are available for real-time monitoring JMeter tests?
- What are the benefits of integrating InfluxDB and Grafana into the load testing stack?
- Which features are provided by Grafana?
- Demonstration of InfluxDB and Grafana using a practice web application
To view the webinar recording, go to:
https://www.rttsweb.com/jmeter-integration-webinar
JMeter webinar - integration with InfluxDB and Grafana
Pointers in c
1. What will be covered
Pointers
Pointer definition
Initialization
Dereferencing Pointers
Constant Pointer
Pointer Arithmetic's
Adding or subtracting integer from pointers.
Pointers and Arrays
Pointers as arguments
Memory Management using Pointers
new operator
delete operator
Lecture 7: Pointers 1
2. Pointers
Pointers are variables like any other type. However they
are also derived type like arrays.
Just like other variables, you need to declare pointers
before using them and there must exist one and only one
definition for each variable of type pointer.
Pointers can be used to hold “memory address ” of other
variables of a given type.
However just like, each variable has a type, pointers also
have type, like
Pointer to an int. It can be used to hold addresses of only and
only int variables (not even unsigned int)
Pointer to a char, hold addresses of only and only char
Pointer to an object of any user defined type such as say
“shape”.
Lecture 7: Pointers 2
3. Why Pointers should have type?
Why type?
Unless you would tell what type of address pointer is pointing to,
compiler would not know how to use (interpret) that pointer. Example:
If pointer to double, that means next eight bytes are holding the double in
a particular way.
If unsigned, that means two bytes, with no sign bit.
If char, means ASCII value in single byte.
To perform what is known as pointer arithmetic’s you need to know
size of element to which pointer is “ pointing”.
To be able to have compile time error checking, making your program
more robust, you need to specify type.
However language gives you freedom to cast it to pointer of most of
the other types, thus giving you all the freedom.
So, type of variable to which it is pointing is firmly attached with
all pointers.
Lecture 7: Pointers 3
4. Defining Pointers
Pointers are a powerful tool and should be used carefully.
Whenever you need to use it, you have to define them first.
Pointer have a name, just like other variables. Same naming
convention, as for variable, is used for pointers.
Name of pointer is different than the name of variable to which
they may be pointing (don’t get confused here).
Example
int *pi, *pj, *pk; // three pointers to int
// with names pi, pj and pk
char *str; // pointer to char
Here ‘*’ is used to indicate it is pointer variable and not int.
Note that * needs to be used for every variable declaration
separately.
So, int *pi, pj; /* defines two variables, pi is pointer to int
and pj is normal int variable and not a pointer */
Lecture 7: Pointers 4
5. Correct Pointer
Definitions
Correct examples of Definitions are:
double* abc; // * can be close to double or abc
double *bcd; // Ok, however you need * with every pointer.
double *cde,* def, * efg; // 3 pointers each of type pointer to double
You can defined pointer to derived or user defined types as well,
However, definition depends upon operator precedence
int *fgh[5]; // Since precedence of [] is higher than *, this is array of
// 5 pointers to int and not pointer to array of 5 ints
int (*ghi)[5]; // This is single pointer to array of 5 ints.
Similarly if say Shape is user defined type than
Shape * hij; // hij is pointer to Shape (UDT, definition of which should
// come before this definition of pointer).
We can also have pointer to pointer
int * * ijk; // ijk is pointer to (pointer to int). I.e we can store address
// of any pointer to int in ijk.
Similarly there could be pointer to pointer to pointer of a type & so on…
Lecture 7: Pointers 5
6. Wrong Pointer Definitions
Wrong Definitions of pointers are:
double abc *; // * can not be after the name
* double bcd; // * can not be before the type name.
double *cde, def; // if we want def to be pointer there
// must be a * before it
pointer * efg; // Type has to be specified (pointer is not a
keyword)
* fgh; // Error, if type is completely missing
Shape *ghi; // if Shape has not been defined so far.
int & ijk; // we cannot use & or other operators in place of *
// & means reference and not pointer
Lecture 7: Pointers 6
7. Pointer Initialization
You need to set proper values (address) to pointers just
like you set values for variables, before you can use them.
This is how you can set proper values for local and global
pointer variables
Initialize them at the time of declaration with address of a
known variable, example
int *pi=&i; /* initialized to address of i. i should only be of
type int and should already be defined or declared in the
current file. i could be local or global variable */
Here ‘&’ is acting as “address of” operator
If not initialized, it can later be assigned an address of any
variable of the same type, before using it
int *pi;
pi=&i; /* assign address. This can be done multiple time. You
may assign it the address of any other variable at any time */
Lecture 7: Pointers 7
8. Dereferencing pointers
Ok, so you have also initialized or assigned the address to
our pointer. Now what?
You can perform following actions
You can dereference the pointer to get the object to which
your pointer is pointing. Example
int *pi=&i;
(*pi)=76; // same as i=76; here * is deference and not pointer
In other words, you can use (*pi), anywhere you can use int
variables, even on left side. You don’t need (), but can be used
for clarity. I.e. you could say *pi=3*4+7;
You can perform pointer arithmetic's. Discussed later
Pointers can be used to pass arguments to function which the
functions can modify (Equivalent to Pass by reference).
Pointers are used to allocate memory at run time as per your
needs (Memory Allocation). Discussed at the end
Lecture 7: Pointers 8
9. Pointer to constant
You can define
Pointer to a const variable, as follows
const int *pi=&i; //also int const* pi
i itself need not be a const variable. It could be any normal
variable, however when referenced through pi, we cannot modify i.
Now you cannot use (*pi) to modify the contents of i. However you
can use it to access the contents of i.
(*pi)=10; // error
(*pi)++; // error
int j= (*pi)+56; // OK as we are not modifying i
You can still make pi point to another variable of type int, example
pi=&j; // ok for pointer to const variable
// Note: when assigning address you should not
// use *pi instead use pi itself.
Lecture 7: Pointers 9
10. Constant Pointer
You can also define const pointer to a variable, as
follows
int *const pi=&i; // use const after ‘*’
It must be initialized (not assigned afterwards) because we are
defining a constant pointer, which can not be assigned later on.
You can modify i using (*pi), as follows
(*pi)=10; // OK, variable is not constant
(*pi)++; // OK
However now pi cannot point to any other variable
pi=&j; // ERROR, constant pointer
Similarly we have const pointer to a const variable
const int * const pi=&i; // or int const * const pi=&i;
Now we cannot modify i through pi or assign address of any other
variable in pi. We can use it only to access value of i at any time.
(*pi)=10; // Error
(*pi)++; // Error
pi=&j; // Error
j = (*pi)+56; // OK
Lecture 7: Pointers 10
11. Pointer Arithmetic
You can add or subtract a integer from all those pointers which
are not declared const pointer, example
int *pi=&i;
pi+=10; // No compiler error, now pi is pointing to
// 10 th int’s address from the address of i
pi++; // pi is further incremented by one
--pi; // decrement pi by one.
pi=pj-j; // where pj is another pointer and j is int
Note: When performing arithmetic it is on pi and not (*pi)
You can subtract two pointers of same type to get an int,
example
int *pi=&i; *pj=&j, k;
k=pi-pj; // value of k would be int
/* it would return number of elements of pointer type and not
number of bytes */
Lecture 7: Pointers 11
12. Pointer Arithmetic
When we perform pointer Arithmetic, Compiler assumes that
the address that our pointer is pointing to belongs to array of
the type of variables to which our pointer belongs.
That is Given
int i, *pi=&i; /* compiler assumes pi contains address of an
array of int’s */
Therefore when we say pi++; Compiler changes the address in
pi so that it is now pointing to next integer, I.e. address which
is 2 bytes from the original address. (compiler does not bother
whether it is actually int or not, it simply assumes it is int and
will try to interpret that memory as int).
So, if we increase the address in double pointer by one, it now
points to next double (I.e. 8 th byte’s address from original
address)
Remember, when we are performing pointer arithmetic it is on
pointer pi and not on (*pi).
Lecture 7: Pointers 12
13. Pointer and Arrays
Pointers and Arrays go side by side. In fact array is
implemented as const pointer
When you define array variable, two things happen
A const pointer is created with the name of the array variable
Enough continuous memory is reserved (allocated) in data
segment (not on heap) and address of its first element is stored
in the array variable (in other words const array pointer is
properly initialized)
Now pointer arithmetic is used to access elements of array
Example
int arr[10]; // array of ten int’s
variable arr is actually implemented as int * const arr and
initialized
to the Address of memory allocated (10 int’s)
Now if you use, for example arr[5]; compiler would replace this
with *((arr)+(5)); This is why index start from 0 and not 1.
i.e., it would dereference the 5th address from the address of first
element, which would be address of 6th element.
Lecture 7: Pointers 13
14. Pointer and Arrays
Example continues…
Note that we cannot change the value of arr itself, but we
can use it’s value to access rest of the elements
Even in case of pointer, you can add or subtract integer
value (or variable) from a pointer and then dereference it
Compiler would simply try to access whatever is there at
the computed address as a type of that pointer
So, if you say
int *pi=&i; // initialize with address of a variable
*(pi+3)=10; // compiler would try to access 6 th and 7 th bytes
from the address of i, as variables of type int. It would not
generate any error message, if those bytes are actually
not int, or if they have not been allocated by your
program
So, it’s the responsibility of programmers to ensure that
you are accessing proper memory locations using
pointers Lecture 7: Pointers 14
15. Pointer as Arrays
So, if they have so many similarities can pointers be used with
similar notation as of array
Why not!
Example
int *pi=&i;
pi[2]=10; // same as *(pi+2)=10;
Hey but you are using address of single variable as address of
array
That’s why I said in beginning, its powerful tool, use carefully.
YES you can and no compiler errors, but surely run time errors
(even collapse of OS)
Compiler cannot differentiate between pointer to single variable
or pointer to array.
So, can array variables be used as pointer notation. Yes, as
long as you are using them as const pointer
int arr[10];
*(arr+i)=67; // same as arr[i]=67;
Lecture 7: Pointers 15
16. Pointer as function
argument
Pointers can be used as a function argument as follows:
say we want to define a function which takes pointer to int as argument
void myFunc(int * pi); // function prototype
In the function body, use pi, as if it has been properly defined &
initialized
void myFunc(int *pi) {
*pi=10; // use pi as defined and initialized pointer
}
At other places, where you need to call that function, you would need to
supply ADDRESS of VARIABLE (or address of constants if the argument
is defined as const pointer)
myFunc(&i); // Ok, whether argument is normal or const pointer
myFunc(&45); // only if argument is defined as const pointer
myFunc(i); // ERROR, supply address of int and not int itself
You may also pass pointer to int (not address of pointer to int)
int i=20,*pi;
pi= &i;
myFunc(pi); // OK, However after this call value of i would change.
myFunc(&pi); // ERROR, don’t supply address of pointer to int
Lecture 7: Pointers 16
17. Memory Management
Using pointers we can take memory management in our hand and we can
directly control lifetime of variables.
I.e. we can create variables whenever we want and destroy them after we
have used them.
Suppose, we want to create a variable in one function say f1(); and then
use them even after that function is finished. This is how we can create a
variable in function f1();
int *pi; // pi is some global pointer to int
void f1() {
pi = new int; // using operator new
// now use pi as we want, it is pointing to an unnamed int
}
Here new operator is used which work as follows
When we use expression new anytype; // anytype could be fundamental,
derived or user defined type
Than new operator allocates enough memory for one variable of type anytype
It than returns the address of the memory which is allocated. We can store
this address in pointer to anytype .
Lecture 7: Pointers 17
18. Releasing Memory
Now using that pointer (I.e. by dereferencing that pointer), we can use
the recently allocated variable as we want.
When we don’t want to use that variable any more, we can release the
allocated memory as follows
delete pi; // delete is an operator, which release memory
Deleting an earlier allocated pointer, more than once is programming
error. Not deleting it even once, though not an error, but leads to
memory leaks which could be bad if your program performs lot of memory
allocation.
Deleting a pointer which is properly initialized with address of a variable
which is not allocated by you, may not lead to run time error, but is
programming error.
int i=10, *pi=&i;
delete pi; // no runtime error but programming error
Pointers can be assigned null value
myClass *ptr; // myClass is some user defined class
ptr=0; // null pointer
delete ptr; // deleting null pointer, even multiple times, has no side
effects
Lecture 7: Pointers 18
19. Allocating Arrays
Using new operator we can even allocate more than one variable
example
int *pi = new int[40]; // allocate 40 int’s and store address of first
pi[3]=10; // int in pi so that using pi, we can use all 40 int’s
pi[39]=20; // now pi just as array of 40 int’s
Since new operator can take expression using variable, we can
dynamically allocate memory as per our requirement. Example
int size;
cout << “Enter size of char array: “;
cin >> size;
char *pd = new char[size]; // array size will be decided at run
time
We can even allocated user defined type using new operator.
Remember, that address returned by new operator is useful till
we want to use the allocated memory and so it should usually
not be stored in local pointer objects, which would be lost at the
end of that function. If so, than we would not be able to
deallocate that memory.Lecture 7: Pointers 19
20. Exercise
There would be a quiz before the next class.
Write a program which will take input of any
number of integers till –1 is entered. It will
than display each separate number that was
input along with number of times it was
input. Interaction with program should be as
follows:
Number: 34
Number: 34
Number: 45
Number: -1
Number 34 was specified 2 times
Number 45 was specified 1 times
Lecture 7: Pointers 20
21. Exercise contd…
Write a program which would make spiral matrix.
Interaction with program should be as follows.
Enter size of matrix (odd): 5
Writing matrix…
17 16 15 14 13
18 5 4 3 12
19 6 1 2 11
20 7 8 9 10
21 22 23 24 25
Can you modify the program so that it also ask for
starting direction and rotation (clockwise or
anticlockwise) and makes matrix as per that direction
and rotation.
Lecture 7: Pointers 21