answersLogoWhite

0


Best Answer

If the pointer is pointing to an array, you would do the exact same and use [], but if it weren't pointing to an array, you can use * to extract data from the pointer.

eg:

int a = 5; //set a to 5

int* b = &a;//set b to the address pointed by b

int result = *b; //extract data b is pointing to (5)

result would then be 5

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do we get values through pointers instead of arrays in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the purpose of using arrays in C language?

The purpose of using arrays in C is to store multiple values in one variable. Then you can make programs that use arrays like lists, printing values from multiple arrays into one line. It take memory in continues block then we can know memory location easily. We can retrieve data quickly.


How do you write a program in c plus plus to swap each half of an array?

Swapping array elements is simple enough. The only issue is what to do with the middle element when there are an odd number of elements. The following program simply leaves it where it is. #include<iostream> #include<vector> template<typename T> void exchange (std::vector<T>& v) { if (v.size()<2) return; size_t left = 0; size_t right = v.size() / 2; if (v.size()%2) ++right; // skip middle element while (right < v.size()) std::swap (v[left++], v[right++]); } int main() { std::vector<unsigned> v {4, 8, 15, 16, 23, 42, 69}; for (auto n : v) std::cout << n << ' '; std::cout << std::endl; exchange (v); for (auto n : v) std::cout << n << ' '; std::cout << std::endl; }


What is difference between Deep copy and shallow copy?

A "shallow" copy is when the member values are physically copied from one object to another, *including* the values of any pointer or reference members. If there are pointer or reference memebrs, then, those poointers or references refer to the *same* objects as the original object, which is usually a bad thing. That's why you want to define a copy constructor and assignment operator for objects that contain pointers or references. It's called a "shallow" copy because only the values of the pointers/references are copied, instead of making copies of those referred-to objects and setting pointers to them. *That* is what would be called a "deep" copy, because it's going "deeper" into the structure, copying everything, not just the first "layer".


What are the advantages of a pointer variable?

Arrays takes consecutive memory space. So, if you have 5 consecutive memory blocks free which is consecutive, an error will occur while creating an array which takes more than 5 blocks of memory. But if you use pointer, then it don't need consecutive memory blocks all the elements can be placed anywhere in memory.


What are the operations that can be performed using a pointer expression?

a. adding and subtracting the integer values b. adding and subtracting the pointers c. incrementing and decrementing the pointers other than tis pointer operations include relational operations such as =,<,>.

Related questions

What is the purpose of using arrays in C language?

The purpose of using arrays in C is to store multiple values in one variable. Then you can make programs that use arrays like lists, printing values from multiple arrays into one line. It take memory in continues block then we can know memory location easily. We can retrieve data quickly.


How do you get difference between two or more arrays in PHP?

The inherit function `array_dif($arrayOne, $arrayTwo, $arrayThree, ...)` is likely what you're looking for. It compares two or more arrays, and returns an array of values that are unique among the arrays.


How does one use JavaScript arrays?

JavaScript arrays is used to generalize multiple values of data and store them in a single variable. This is a useful software in most programming languages.


How do you write a program in c plus plus to swap each half of an array?

Swapping array elements is simple enough. The only issue is what to do with the middle element when there are an odd number of elements. The following program simply leaves it where it is. #include<iostream> #include<vector> template<typename T> void exchange (std::vector<T>& v) { if (v.size()<2) return; size_t left = 0; size_t right = v.size() / 2; if (v.size()%2) ++right; // skip middle element while (right < v.size()) std::swap (v[left++], v[right++]); } int main() { std::vector<unsigned> v {4, 8, 15, 16, 23, 42, 69}; for (auto n : v) std::cout << n << ' '; std::cout << std::endl; exchange (v); for (auto n : v) std::cout << n << ' '; std::cout << std::endl; }


What is the purpose of initialising an array?

Arrays are variables, so your question is: What is the purpose of initialising a variable? Answer: assigning initial values to them.


What is the technique used for adding and subtracting values from the pointers address in order to access other memory locations called?

WikiAnswers does not provide information about illegal acts, such as cracking other computers through pointer manipulation.


Is array list value type or reference type?

Arrays are reference type. array values are always pass by reference.


What is difference between Deep copy and shallow copy?

A "shallow" copy is when the member values are physically copied from one object to another, *including* the values of any pointer or reference members. If there are pointer or reference memebrs, then, those poointers or references refer to the *same* objects as the original object, which is usually a bad thing. That's why you want to define a copy constructor and assignment operator for objects that contain pointers or references. It's called a "shallow" copy because only the values of the pointers/references are copied, instead of making copies of those referred-to objects and setting pointers to them. *That* is what would be called a "deep" copy, because it's going "deeper" into the structure, copying everything, not just the first "layer".


Is there a difference between an array and a pointer?

Array is a data type which can be represented as a[1],a[2],a[3].... Pointer is also a data type. The speciality of pointer is instead of address of the variable it will give the reference to the address of the variable. E.g. int *test Here test is a pointer variable. which will be the reference to the address == One dimensional arrays are constant pointers, you cannot change their values, eg: int a[10], *pa = &a[3]; p[0]= a[0]; // ok a[0]= p[0]; // ok p= a; // ok a= p; // INVALID for a is constant


What are the advantages of a pointer variable?

Arrays takes consecutive memory space. So, if you have 5 consecutive memory blocks free which is consecutive, an error will occur while creating an array which takes more than 5 blocks of memory. But if you use pointer, then it don't need consecutive memory blocks all the elements can be placed anywhere in memory.


What are the operations that can be performed using a pointer expression?

a. adding and subtracting the integer values b. adding and subtracting the pointers c. incrementing and decrementing the pointers other than tis pointer operations include relational operations such as =,<,>.


How arrays are created in java?

Arrays are created just like other variables in Java. Ex: int[] a; // declares an array of integers a = new int[10]; // allocates memory for 10 integers a[0] = 100; // initialize first element a[1] = 200; // initialize second element Arrays are homogenous data types and hence they can contain values of only one type. If you create an integer array it can hold only integer data type values. If you try to assign values to nonexistent locations like a[15] it will throw an index out of bounds exception.