Question

In: Computer Science

The concept of pointers in C++ is inherited from the C language, which relies extensively on the use of pointers.

 

Topic: The concept of pointers in C++ is inherited from the C language, which relies extensively on the use of pointers. What are the advantages and disadvantages of having the functionality of pointers in a programming language?

Solutions

Expert Solution

Pointer Variable:

A pointer variable is a special type of variable that is used to store the address of another variable which has a similar data type as the pointer data type. The dereferenced operator '*' is used to access the value stored at that location that is stored by the pointer variable.

For example:

int a = 10;

int *b = &a;

Here, the variable 'b' is a pointer variable that stores the address of an integer type variable.

Advantages:

  • The use of pointer reduce the source code and improve performance.
  • The multiple values can be returned by using the pointer.
  • The array and the string can be passed to a function more efficiently.
  • It is used to manage dynamic memory allocation.


Disadvantages:

  • Pointer can cause a segmentation fault.
  • The dynamically allocated memory must be freed explicitly to avoid the memory leakage problem.
  • The illegal use of pointer may corrupt the memory.
  • Pointers are slower as compare to the normal variables.

Related Solutions

this program is to be done in c language. Using Pointers Create a program pointerTester.c to...
this program is to be done in c language. Using Pointers Create a program pointerTester.c to experiment with pointers. Implement the following steps one by one in your program: YOU NEED TO ANSWER QUESTION Use printf to print your answers at the end(after 12). 1. Declare three integer variables a, b and c. Initialize them to 0, 100 and 225, respectively. 2. Print the value of each variable and its address. 3. Add the following declaration to your code: int...
Write this program in C++ language. Use the concept of structures. DO NOT use vectors. Q...
Write this program in C++ language. Use the concept of structures. DO NOT use vectors. Q (4) Create a structure called time. Its three members, all type int, should be called hours, minutes, and seconds. Write a program that prompts the user to enter a time value in hours, minutes, and seconds. This should be in 12:59:59 format. This entire input should be assigned first to a string variable. Then the string should be tokenized thereby assigning the 1st token...
Effective auscultation of the lungs relies on knowledge of which which anatomical concept ?
Effective auscultation of the lungs relies on knowledge of which which anatomical concept ?
Use JAVA language. Using the switch method concept create a program in which you have an...
Use JAVA language. Using the switch method concept create a program in which you have an artist (singer) and the list of his or her songs. Add 18 songs. Then alter the script to achieve the following in each test run: a) Print all the songs. b) Print only song 15. c) Print only song 19.
Write a complete C program that searches an element in array using pointers. Please use the...
Write a complete C program that searches an element in array using pointers. Please use the function called search to find the given number. //Function Prototype void search (int * array, int num, int size)
Don't use vectors use pointers ,classes & objects, functions and loop etc only C++ PROGRAM Following...
Don't use vectors use pointers ,classes & objects, functions and loop etc only C++ PROGRAM Following is a partial implementation of Set class. You are required to enhance and implement the following missing functions from the implementation: A) UNION B) reset C) intersection D) difference A SAMPLE driver program : int a1[] = {10,5,7,3,9}; Set s1(5); s1.insert(a1,5); s1.print("s1"); int a2[] = {2,9,6}; Set s2(3); s2.insert(a2,3); s2.print("s2"); Set s3 = s1.unionset(s2); Set s4 = s1.intersection(s2); Set s5 = s1.difference(s2); s3.print("s3"); s4.print("s4");...
CODE IN C PLEASE Ask for user to input 4 different numbers Use pointers in calculations...
CODE IN C PLEASE Ask for user to input 4 different numbers Use pointers in calculations instead of variables to calculate the sum of those 4 numbers Print the sum Use a pointer to a pointer for print operation
C programming 4. Exploring Pointers and Use of Arrays [15 pts] In a shell environment, programs...
C programming 4. Exploring Pointers and Use of Arrays [15 pts] In a shell environment, programs are often executed using command lines arguments. For example: g++ -o cm03_la01 cm03_la01.c. In C such program can be develop using a standard for which the main program has two parameters as follows: int main (int argc, char * argv[ ]) { /*program here */ } 3 Because of the equivalence between pointers and arrays, the above C code can also be written as...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing chess himself to practice his abilities. The chess that Jojo played was N × N. When Jojo was practicing, Jojo suddenly saw a position on his chessboard that was so interesting that Jojo tried to put the pieces of Rook, Bishop and Knight in that position. Every time he put a piece, Jojo counts how many other pieces on the chessboard can be captured...
Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data...
Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data structures (queues, lists, STs, hashtables etc.) Have a unit test implemented in main(). And comment every code. Show examples from the executions. Assume that the edges defined by the vertex pairs in the data base are one-way. Question: Write a program that can answer if there is a path between any to vertices. For the vertex pairs use this as your input example: AL...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT