Skip to main content
Post Made Community Wiki by user2528
added 97 characters in body
Source Link
Jonathan Henson
  • 5.1k
  • 3
  • 29
  • 33

One simple way is in Polymorphism. Polymorphism only works with pointers.

Also, you use pointers any time you need dynamic memory allocation. In C, this usually happens when you need to store data into an array but you do not know the size at compile time. You would then call malloc to allocate the memory and a pointer to access it. Also, whether you know it or not, when you use an array you are using pointers.

for(int i = 0; i < size; i++)
   std::cout << array[i];

is the equivalent of

for(int i = 0; i < size; i++)
   std::cout << *(array + i);

This knowledge allows you to do really cool things like copy an entire array in one line:

while( (*array1++ = *array2++) != '\0')

In c++, you use new to allocate memory for an object and store it into a pointer. You do this anytime you need to create an object during run-time instead of during compile time (i.e. a method creates a new object and stores it into a list).

To understand pointers better:

  1. Find some projects that play around with traditional c-strings and arrays.

  2. Find some projects that use inheritance.

  3. Here is the project that I cut my teeth on:

Read in two n x n matrices from a file and perform the basic vector space operations on them and print their result to the screen.

To do this, you have to use dynamic arrays and refer to your arrays by pointers since you will have two arrays of arrays (multi-dimensional dynamic arrays). After you finish that project, you will have a pretty good idea how to use pointers.

One simple way is in Polymorphism. Polymorphism only works with pointers.

Also, you use pointers any time you need dynamic memory allocation. In C, this usually happens when you need to store data into an array but you do not know the size at compile time. You would then call malloc to allocate the memory and a pointer to access it. Also, whether you know it or not, when you use an array you are using pointers.

In c++, you use new to allocate memory for an object and store it into a pointer. You do this anytime you need to create an object during run-time instead of during compile time (i.e. a method creates a new object and stores it into a list).

To understand pointers better:

  1. Find some projects that play around with traditional c-strings and arrays.

  2. Find some projects that use inheritance.

  3. Here is the project that I cut my teeth on:

Read in two n x n matrices from a file and perform the basic vector space operations on them and print their result to the screen.

To do this, you have to use dynamic arrays and refer to your arrays by pointers since you will have two arrays of arrays (multi-dimensional dynamic arrays). After you finish that project, you will have a pretty good idea how to use pointers.

One simple way is in Polymorphism. Polymorphism only works with pointers.

Also, you use pointers any time you need dynamic memory allocation. In C, this usually happens when you need to store data into an array but you do not know the size at compile time. You would then call malloc to allocate the memory and a pointer to access it. Also, whether you know it or not, when you use an array you are using pointers.

for(int i = 0; i < size; i++)
   std::cout << array[i];

is the equivalent of

for(int i = 0; i < size; i++)
   std::cout << *(array + i);

This knowledge allows you to do really cool things like copy an entire array in one line:

while( (*array1++ = *array2++) != '\0')

In c++, you use new to allocate memory for an object and store it into a pointer. You do this anytime you need to create an object during run-time instead of during compile time (i.e. a method creates a new object and stores it into a list).

To understand pointers better:

  1. Find some projects that play around with traditional c-strings and arrays.

  2. Find some projects that use inheritance.

  3. Here is the project that I cut my teeth on:

Read in two n x n matrices from a file and perform the basic vector space operations on them and print their result to the screen.

To do this, you have to use dynamic arrays and refer to your arrays by pointers since you will have two arrays of arrays (multi-dimensional dynamic arrays). After you finish that project, you will have a pretty good idea how to use pointers.

added 97 characters in body
Source Link
Jonathan Henson
  • 5.1k
  • 3
  • 29
  • 33

One simple way is in Polymorphism. Polymorphism only works with pointers. Any

Also, you use pointers any time you need dynamic memory allocation:. In C, this usually happens when you need to store data into an array but you do not know the size at compile time. You would then call malloc to allocate the memory and a pointer to access it. Also, whether you know it or not, when you use an array you are using pointers. 

In c++, you use new to allocate memory for an object and store it into a pointer. You do this anytime you need to create an object during run-time instead of during compile time (i.e. a method creates a new object and stores it into a list).

To understand thempointers better:

  1. Find some projects that play around with traditional c-strings and arrays.

  2. Find some projects that use inheritance.

  3. Here is the project that I cut my teeth on:

Read in two n x n matrices from a file and perform the basic vector space operations on them and print their result to the screen.

To do this, you have to use dynamic arrays and refer to your arrays by pointers since you will have two arrays of arrays (multi-dimensional dynamic arrays). After you finish that project, you will have a pretty good idea how to use pointers.

One simple way is in Polymorphism. Polymorphism only works with pointers. Any time you need dynamic memory allocation: In C, this usually happens when you need to store data into an array but you do not know the size at compile time. You would then call malloc to allocate the memory and a pointer to access it. Also, whether you know it or not, when you use an array you are using pointers. In c++, you use new to allocate memory for an object and store it into a pointer. You do this anytime you need to create an object during run-time instead of during compile time.

To understand them better:

  1. Find some projects that play around with traditional c-strings and arrays.

  2. Find some projects that use inheritance.

  3. Here is the project that I cut my teeth on:

Read in two n x n matrices from a file and perform the basic vector space operations on them and print their result to the screen.

To do this, you have to use dynamic arrays and refer to your arrays by pointers since you will have two arrays of arrays (multi-dimensional dynamic arrays). After you finish that project, you will have a pretty good idea how to use pointers.

One simple way is in Polymorphism. Polymorphism only works with pointers.

Also, you use pointers any time you need dynamic memory allocation. In C, this usually happens when you need to store data into an array but you do not know the size at compile time. You would then call malloc to allocate the memory and a pointer to access it. Also, whether you know it or not, when you use an array you are using pointers. 

In c++, you use new to allocate memory for an object and store it into a pointer. You do this anytime you need to create an object during run-time instead of during compile time (i.e. a method creates a new object and stores it into a list).

To understand pointers better:

  1. Find some projects that play around with traditional c-strings and arrays.

  2. Find some projects that use inheritance.

  3. Here is the project that I cut my teeth on:

Read in two n x n matrices from a file and perform the basic vector space operations on them and print their result to the screen.

To do this, you have to use dynamic arrays and refer to your arrays by pointers since you will have two arrays of arrays (multi-dimensional dynamic arrays). After you finish that project, you will have a pretty good idea how to use pointers.

Source Link
Jonathan Henson
  • 5.1k
  • 3
  • 29
  • 33

One simple way is in Polymorphism. Polymorphism only works with pointers. Any time you need dynamic memory allocation: In C, this usually happens when you need to store data into an array but you do not know the size at compile time. You would then call malloc to allocate the memory and a pointer to access it. Also, whether you know it or not, when you use an array you are using pointers. In c++, you use new to allocate memory for an object and store it into a pointer. You do this anytime you need to create an object during run-time instead of during compile time.

To understand them better:

  1. Find some projects that play around with traditional c-strings and arrays.

  2. Find some projects that use inheritance.

  3. Here is the project that I cut my teeth on:

Read in two n x n matrices from a file and perform the basic vector space operations on them and print their result to the screen.

To do this, you have to use dynamic arrays and refer to your arrays by pointers since you will have two arrays of arrays (multi-dimensional dynamic arrays). After you finish that project, you will have a pretty good idea how to use pointers.