Concept explainers
Pointer:
Pointer, the name itself references the purpose of the pointer. Pointers point to a location in memory.
- Pointer is a special type of variable to store the address of the memory location, which can be accessed later.
- If an asterisk “*” operator is present before the variable, then that variable is referred as pointer variable.
- It is also called as dereferencing or indirection operator.
- Pointer is just a type of variable that stores the addresses of other variables.
- Using pointers, we can access the address of a variable; the data stored in that variable can be retrieved.
Syntax of pointer variable declaration:
<variable-type> *<variable-name>;
Adding a value to a pointer variable:
When a pointer variable is added it is similar to adding number of time the size of the pointer variable that is stored.
Example:
//declaring a pointer variable
int *a;
//incrementing the pointer value by 1
a++;
In the above snippet the pointer variable is incremented by “1” means, the size of the pointer variable is being increased in terms of their size.
1 * 2 = 2
Therefore, additional 2 bytes will be added to the pointer variable “a” after incrementing it by “1”.
Want to see the full answer?
Check out a sample textbook solutionChapter 9 Solutions
Starting Out with C++ from Control Structures to Objects (8th Edition)
- please solve the problem using c language pointers please indicate the print and the intended output <stdio.h> int main(){} char letters[26]; char *pc1 = letters; /* Equivalent pointer values. */ char *pc2 = &letters; char *pc3 = &letters[0]; letters[4] = "e"; /* Equivalent indexes. */ pc1[4] = ’e’; *(letters + 4) = "e"; *(pc2 + 4) = "e"; pc3 = &letters[10]; /* Equivalent addresses. */ pc3 = &pc1[10]; pc3 = letters + 10; pc3 = pc2 + 10; }arrow_forwardGiven the code segment below, what is the value that is passed to func() given the function call? Assume that func() is defined. If it is an invalid access, write INVALID (in all capital letters) as your answer. Assume that the array aData[] is associated to the memory address 1010 (in decimal). If the value is an address, then indicate the memory address in decimal. double aData[15] = {0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9};func(aData + 2);arrow_forwardC++ Write a program in which a pointer is declared to hold the address of a variable and outputs the address of that variable. Your output should look like this: This address variable named (name of variable) is (address of the variable).arrow_forward
- 1.Code a descriptor that contains a starting address 8A0000H and an ending address 8A1119H. If DS = 1095 and expands downward and can be written, what is the entry level, descriptor table used, and the RPL?arrow_forward1)Answer the question with the correct option A) Which of the following assigns to the pointer p to the address of value? options are given p = value; *p = &value; p = &value; p = &value;arrow_forwardConsider the following C++ code snippet: int cards[3]; for (int i = 0; i < 3; i++) cards[i] = 0; Choose the best statement: A) This code will compile and run but causes an out-of-range memory write. B) This code will compile and has no apparent issues. C) This code will not compile as written. D) This code shows an example of dynamic memory allocation.arrow_forward
- Assume that pointer ptr is a pointer to a double, and has initial value of 0xfc0f. What is the value of ptr after the pointer has been decremented? (assume a 4 byte double) Group of answer choices 0xfb0e 0xfc13 0xfc0b 0xfc0earrow_forwardWrite a C program that uses the following: a main() to read two integer values from the user, val1 and val2, and prints the returned value from swap().a swap() that uses call by reference (takes the addresses into pointers) to swap values, and prints their values after the swap "num1 = # and num2 = #". This function returns the largest of the two values. If these are equal, it returns their sum.arrow_forwardWhen a variable is stored in memory, it is associated with an address. To obtain the address of avariable, the & operator can be used. For example, &a gets the memory address of variable a.Let's try some examples.Write a C program addressOfScalar.c by inserting the code below in the main function. 1 // intialize a char variable, print its address and the next address2 char charvar = 'a';3 printf("address of charvar = %p\n", (void *)(&charvar));4 printf("address of charvar - 1 = %p\n", (void *)(&charvar - 1));5 printf("address of charvar + 1 = %p\n", (void *)(&charvar + 1));67 // intialize an int variable, print its address and the next address8 double doublevar = 1.0;9 printf("address of doublevar = %p\n", (void *)(&doublevar));10 printf("address of doublevar - 1 = %p\n", (void *)(&doublevar - 1));11 printf("address of doublevar + 1 = %p\n", (void *)(&doublevar + 1)); Questions:1) Run the C program, attach a screenshot of the output in the answer…arrow_forward
- // Program 4.6.1 #include <iostream>using namespace std;int main (){int X = 5, Y = 15; int * p1, * p2;p1 = &X; // p1 = address of Xp2 = &Y; // p2 = address of Y*p1 = 10; // value pointed by p1 = 10*p2 = *p1; // value pointed by p2 = value pointed by p1p1 = p2; // p1 = p2 (value of pointer is copied)*p1 = 40; // value pointed by p1 = 20cout << "X is " << X << endl;cout << "Y is " << Y << endl;return 0;} TASK 1. Explain in details what the program does? 2. What is the outputarrow_forwardWrite a program that will take n floating point numbers as input and print the sum, average and maximum of the numbers. Use dynamic memory allocation and pointers to do the task. Sample input file: 5 12 24 34 45 56 Sample output file: Sum : 171.0 Average : 34.2 Maximum : 56arrow_forwardWhat is the signature of a pointer that can only point to a fixed memory location?arrow_forward
- Systems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr