What is an array of pointers?

respectSign
This is a recommends products dialog
Top Suggestions
Starting at
View All >
Language
French
English
LangEntry.ChineseTaiwan
ไทย
LangEntry.Dutch
German
繁體中文
Country
Hi
All
Sign In / Create Account
language Selector,${0} is Selected
Join & Shop in Lenovo Pro
Register at Education Store
Pro Tier Benefits
• Save up to an extra 5% on Think everyday pricing
• Purchase up to 10 systems per order (5 more than Lenovo.com)
• Spend $10K, advance to Plus Tier with increased benefits
Plus Tier Benefits
• Save up to an extra 6% on Think everyday pricing
• Purchase up to 25 systems per order (20 more than Lenovo.com)
• Spend $50K, advance for free to Elite Tier with increased benefits
• Take advantage of flexible payment options with TruScale Device as a Service. Learn More >
Elite Tier Benefits
• Save up to an extra 7% on Think everyday pricing
• Purchase up to 50 systems per order (45 more than Lenovo.com)
• Take advantage of flexible payment options with TruScale Device as a Service. Learn More >
Partner Benefits
• Access to Lenovo's full product portfolio
• Configure and Purchase at prices better than Lenovo.com
View All Details >
spend
more to reach
PRO Plus
PRO Elite
Congratulations, you have reached Elite Status!
Pro for Business
Delete icon Remove icon Add icon Reload icon
TEMPORARILY UNAVAILABLE
DISCONTINUED
Temporary Unavailable
Cooming Soon!
. Additional units will be charged at the non-eCoupon price. Purchase additional now
We're sorry, the maximum quantity you are able to buy at this amazing eCoupon price is
Sign in or Create an Account to Save Your Cart!
Sign in or Create an Account to Join Rewards
Temporarilyunavailable
Discontinued
comingsoon
minicart_error_please_view
View Cart
Your cart is empty! Don’t miss out on the latest products and savings — find your next favorite laptop, PC, or accessory today.
Remove
item(s) in cart
Some items in your cart are no longer available. Please visit cart for more details.
has been deleted
Please review your cart as items have changed.
of
Contains Add-ons
Subtotal
Proceed to checkout
Yes
No
Popular Searches
What are you looking for today ?
Quick Links
Recent Searches
Hamburger Menu
skip to main content
{"arrowColor":"","backgroundColor":"#e6f4fa","divideColor":"#DBDBDB","sideMsg":"","data":[{"pcInfo":"","mAndTabInfo":"","bannerInfo":{"t_id":"Pagef311e260-e1cd-445f-aa83-d721e94cc7bd","language":{"en_us":"%3Cp%3E%3Cstrong%20style%3D%22text-wrap%3A%20wrap%3B%22%3E%3C%2Fstrong%3E%3Cstrong%3E%3C%2Fstrong%3E%3Cstrong%3E%3C%2Fstrong%3E%3Cstrong%3EMemorial%20Day!%3C%2Fstrong%3E%20Save%20up%20to%20%7BsavingPercent%7D%20on%20laptops%20%26amp%3B%20accessories!%20Plus%2C%20free%20shipping%20sitewide.%3Cspan%20style%3D%22text-wrap%3A%20wrap%3B%22%3E%26nbsp%3B%3C%2Fspan%3E%3Ca%20href%3D%22%2Fd%2Fdeals%2Fdoorbusters%2F%3FIPromoID%3DLEN944203%22%20target%3D%22_self%22%20textvalue%3D%22Shop%20Now%20%26gt%3B%22%3E%3Cstrong%3EShop%20Now%20%26gt%3B%3C%2Fstrong%3E%3C%2Fa%3E%3C%2Fp%3E","en":"%3Cp%3E%3Cstrong%20style%3D%22text-wrap%3A%20wrap%3B%22%3EMemorial%20Day!%3C%2Fstrong%3E%3Cspan%20style%3D%22text-wrap%3A%20wrap%3B%22%3E%26nbsp%3BSave%20up%20to%20%7BsavingPercent%7D%20on%20laptops%20%26amp%3B%20accessories!%20Plus%2C%20free%20shipping%20sitewide.%3C%2Fspan%3E%3Cspan%20style%3D%22text-wrap%3A%20wrap%3B%22%3E%26nbsp%3B%3C%2Fspan%3E%3Ca%20href%3D%22%2Fd%2Fdeals%2Fdoorbusters%2F%3FIPromoID%3DLEN944203%22%20target%3D%22_self%22%20textvalue%3D%22Shop%20Now%20%26gt%3B%22%20style%3D%22text-wrap%3A%20wrap%3B%22%3E%3Cstrong%3EShop%20Now%20%26gt%3B%3C%2Fstrong%3E%3C%2Fa%3E%3C%2Fp%3E"},"id":"Pagef311e260-e1cd-445f-aa83-d721e94cc7bd"},"gInfo":""},{"pcInfo":"","mAndTabInfo":"","bannerInfo":{"t_id":"Pagef420f92c-4cfa-43fa-b824-c3bcfbc50cfa","language":{"en_us":"%3Cp%3E%3Cstrong%3E%3C%2Fstrong%3E%3Cstrong%3EShopping%20for%20a%20business%3F%3C%2Fstrong%3E%20New%20Lenovo%20Pro%20members%20get%20%24100%20off%20first%20order%20of%20%241%2C000%2B%2C%20exclusive%20savings%20%26amp%3B%201%3A1%20tech%20support.%26nbsp%3B%3Ca%20href%3D%22%2Fbusiness%2Fbenefits%2F%3FipromoID%3DLEN818484%22%20target%3D%22_self%22%20textvalue%3D%22Learn%20More%20%26gt%3B%22%3E%3Cstrong%3ELearn%20More%20%26gt%3B%3C%2Fstrong%3E%3C%2Fa%3E%3C%2Fp%3E","en":"%3Cp%3E%3Cstrong%20style%3D%22text-wrap%3A%20wrap%3B%22%3EShopping%20for%20a%20business%3F%3C%2Fstrong%3E%3Cspan%20style%3D%22text-wrap%3A%20wrap%3B%22%3E%26nbsp%3BNew%20Lenovo%20Pro%20members%20get%20%24100%20off%20first%20order%20of%20%241%2C000%2B%2C%20exclusive%20savings%20%26amp%3B%201%3A1%20tech%20support.%26nbsp%3B%3C%2Fspan%3E%3Ca%20href%3D%22%2Fbusiness%2Fbenefits%2F%3FipromoID%3DLEN818484%22%20target%3D%22_self%22%20textvalue%3D%22Learn%20More%20%26gt%3B%22%3E%3Cstrong%3ELearn%20More%20%26gt%3B%3C%2Fstrong%3E%3C%2Fa%3E%3C%2Fp%3E"},"id":"Pagef420f92c-4cfa-43fa-b824-c3bcfbc50cfa"},"gInfo":""},{"pcInfo":"","mAndTabInfo":"","bannerInfo":{"t_id":"Pagec1c30bb7-e52d-44f0-a816-8281055dc14c","language":{"en_us":"%3Cp%3E%3Cspan%20style%3D%22text-wrap%3A%20wrap%3B%22%3ENeed%20it%20today%3F%20Buy%20online%2C%20pick%20up%20select%20products%20at%20Best%20Buy.%26nbsp%3B%3C%2Fspan%3E%3Ca%20href%3D%22%2Fd%2Fbopis%2F%3FIPromoID%3DLEN775727%22%20target%3D%22_self%22%20textvalue%3D%22Shop%20Pick%20Up%20%26gt%3B%22%3E%3Cstrong%3E%3Cspan%20style%3D%22text-wrap%3A%20nowrap%3B%22%3EShop%20Pick%20Up%20%26gt%3B%3C%2Fspan%3E%3C%2Fstrong%3E%3C%2Fa%3E%3C%2Fp%3E","en":"%3Cp%3E%3Cspan%20style%3D%22text-wrap%3A%20wrap%3B%22%3ENeed%20it%20today%3F%20Buy%20online%2C%20pick%20up%20select%20products%20at%20Best%20Buy.%26nbsp%3B%3C%2Fspan%3E%3Ca%20href%3D%22%2Fd%2Fbopis%2F%3FIPromoID%3DLEN775727%22%20target%3D%22_self%22%20textvalue%3D%22Shop%20Pick%20Up%20%26gt%3B%22%3E%3Cstrong%3E%3Cspan%20style%3D%22text-wrap%3A%20nowrap%3B%22%3EShop%20Pick%20Up%20%26gt%3B%3C%2Fspan%3E%3C%2Fstrong%3E%3C%2Fa%3E%3C%2Fp%3E"},"id":"Pagec1c30bb7-e52d-44f0-a816-8281055dc14c"},"gInfo":""},{"pcInfo":"","mAndTabInfo":"","bannerInfo":{"t_id":"Page4ec30f93-7700-4071-bac9-ba50375056be","language":{"en_us":"%3Cp%3E%3Cstrong%3E%3Cspan%20style%3D%22text-wrap%3A%20wrap%3B%22%3E%3C%2Fspan%3E%3C%2Fstrong%3E%3Cstrong%3E%3C%2Fstrong%3E%3C%2Fp%3E%3Cp%3E%3Cspan%20style%3D%22text-wrap%3A%20nowrap%3B%22%3E%3C%2Fspan%3E%3C%2Fp%3E%3Cp%3E%3Cstrong%3E%3Cspan%20style%3D%22text-wrap%3A%20nowrap%3B%22%3E%3C%2Fspan%3E%3C%2Fstrong%3E%3Cstrong%3EMy%20Lenovo%20Rewards!%3C%2Fstrong%3E%20Join%20for%20free%20or%20sign%20in%20to%20your%20account%20and%20earn%202X%20rewards%20(that%26%2339%3Bs%206%25%20back).%20Hurry%2C%20ends%205%2F27%26nbsp%3B%3Ca%20href%3D%22%2Frewards%2F%3FIPromoID%3DLEN775755%22%20target%3D%22_self%22%3E%3Cstrong%3EJoin%20for%20Free%26nbsp%3B%26gt%3B%3C%2Fstrong%3E%3C%2Fa%3E%3C%2Fp%3E","en":"%3Cp%3E%3Cstrong%20style%3D%22text-wrap%3A%20wrap%3B%22%3EMy%20Lenovo%20Rewards!%3C%2Fstrong%3E%3Cspan%20style%3D%22text-wrap%3A%20wrap%3B%22%3E%26nbsp%3B%3C%2Fspan%3E%3Cspan%20style%3D%22text-wrap%3A%20wrap%3B%22%3EJoin%20for%20free%20or%20sign%20in%20to%20your%20account%20and%20earn%202X%20rewards%20(that%26%2339%3Bs%206%25%20back).%20Hurry%2C%20ends%205%2F27%3C%2Fspan%3E%3Cspan%20style%3D%22text-wrap%3A%20wrap%3B%22%3E%26nbsp%3B%3C%2Fspan%3E%3Ca%20href%3D%22%2Frewards%2F%3FIPromoID%3DLEN775755%22%20target%3D%22_self%22%20style%3D%22text-wrap%3A%20wrap%3B%22%3E%3Cstrong%3EJoin%20for%20Free%26nbsp%3B%26gt%3B%3C%2Fstrong%3E%3C%2Fa%3E%3C%2Fp%3E"},"id":"Page4ec30f93-7700-4071-bac9-ba50375056be"},"gInfo":""},{"pcInfo":"","mAndTabInfo":"","bannerInfo":{"t_id":"Pageb792efa9-6abb-449e-abc4-7121ef03a947","language":{"en_us":"%3Cp%3EBad%20credit%20or%20no%20credit%3F%20No%20problem!%20Katapult%20offers%20a%20simple%20lease%20to%20own%20payment%20option%20to%20help%20get%20what%20you%20need.%20%3Ca%20href%3D%22%2Flandingpage%2Flenovo-financing-options%2F%3FIPromoID%3DLEN771093%22%20target%3D%22_self%22%3E%3Cstrong%3ESee%20if%20you%20Prequalify%20%26gt%3B%3C%2Fstrong%3E%3C%2Fa%3E%3C%2Fp%3E","en":"%3Cp%3E%3Cspan%20style%3D%22text-wrap%3A%20wrap%3B%22%3EBad%20credit%20or%20no%20credit%3F%20No%20problem!%20Katapult%20offers%20a%20simple%20lease%20to%20own%20payment%20option%20to%20help%20get%20what%20you%20need.%26nbsp%3B%3C%2Fspan%3E%3Ca%20href%3D%22%2Flandingpage%2Flenovo-financing-options%2F%3FIPromoID%3DLEN771093%22%20target%3D%22_self%22%20style%3D%22text-wrap%3A%20wrap%3B%22%3E%3Cstrong%3ESee%20if%20you%20Prequalify%20%26gt%3B%3C%2Fstrong%3E%3C%2Fa%3E%3C%2Fp%3E"},"id":"Pageb792efa9-6abb-449e-abc4-7121ef03a947"},"gInfo":""}],"autoRun":true,"displayTerminal":"pc","isShowDivide":true}

What is an array of pointers?

An array of pointers is a data structure in which the elements of the array are pointers. Instead of holding data directly, each element in the array holds the memory address (pointer) of another data element. This allows for the creation of an array where each element can point to a different location in memory, typically pointing to other variables or data structures. It allows you to manage multiple memory locations through one array, and it's commonly used in languages like C and C++.

How do I declare an array of pointers?

To declare an array of pointers, you'd specify the pointer type first, followed by the array name and its size. In C or C++, you might do something like int *arr[5];, which declares an array of 5 pointers to integers.

Can I initialize an array of pointers at the time of declaration?

Yes, you can initialize an array of pointers at the time of declaration. For example, you could write int *arr[] = {&x, &y, &z}; where x, y, z are integers already declared in your code. This will store the addresses of x, y, z in the array.

What are the common use-cases for arrays of pointers?

Arrays of pointers are particularly useful when you're working with strings, dynamic memory allocation, or when you want to create an array of different-sized arrays. They're also handy for function pointers, allowing you to call different functions through your array elements.

Does the array size have to be fixed?

In languages like C and C++, the size of the array should be fixed at compile-time unless you're dealing with dynamic memory allocation. However, in some modern languages, arrays can be dynamically resized, but those aren't technically arrays of pointers in the C/C++ sense.

How do I access the values pointed to by the pointers in the array?

To access the values pointed to by the pointers in an array, you'd first use the array index to access the pointer, and then the dereference operator to get the value. In C/C++, *arr[2] would get you the value pointed to by the third pointer in the array arr.

Can I have an array of pointers to arrays?

Yes, you can have an array of pointers to arrays. In this setup, each pointer in the array points to the first element of another array. It's a way to create a jagged array where the "rows" can have different lengths.

Could arrays of pointers be multidimensional?

Absolutely, you can have a multidimensional array of pointers. This gets a bit complex to visualize, but think of it as an array of arrays, where each inner array is itself an array of pointers. You'd use multiple square brackets to access elements, like arr[2][3].

When would it be beneficial to use an array of pointers instead of a regular array?

When you have elements of different sizes or types, an array of pointers is advantageous. Also, if you're pointing to large data structures, it can be more memory-efficient to store pointers rather than the structures themselves.

How do I sort an array of pointers?

You can sort an array of pointers just like a regular array, but you'd be sorting the addresses they point to, not the values. If you want to sort by the pointed-to values, you'll need to dereference the pointers during your comparison in your sorting algorithm.

Can arrays of pointers be used with structs?

Yes, arrays of pointers can point to structs. It's commonly done when you have an array of complex data types. You can then access the struct members through the pointers, like arr[i]->member.

How do I free the memory allocated to an array of pointers?

If you've dynamically allocated memory that the pointers in your array point to, you'll need to loop through the array and use free() for each pointer in C or delete in C++. After that, you can free the array itself if it's also dynamically allocated.

Is it possible to have an array of function pointers?

Absolutely, an array of function pointers is a neat way to call different functions via array indexing. Each element in the array will point to a function, and you can call it using the array index and parentheses, like arr[2](args).

How do I pass an array of pointers to a function?

To pass an array of pointers to a function, you define the function parameter to match the type and size (optional) of the array. In C/C++, a function to accept an array of pointers to integers could look like void myFunction(int *arr[], int size).

What happens if a pointer in my array points to invalid memory?

If a pointer in your array points to invalid memory, accessing it will result in undefined behavior, which could range from your program crashing to subtle bugs. Always make sure your pointers are initialized and point to valid memory locations.

How do I traverse an array of pointers?

Traversing an array of pointers is similar to navigating a regular array; you'd typically use a loop. The difference is in how you access the values. When you reach each pointer, you'd dereference it to get the value it points to. This allows you to perform operations on the actual data instead of the memory addresses. If you're pointing to complex types like structures or objects, you can access their members directly through the pointer, streamlining the process.

Is it more efficient to use an array of pointers rather than an array of objects?

Efficiency depends on the use-case. An array of pointers can save memory if the objects you're working with are large and only a few are accessed frequently. Rather than storing full copies, you store addresses, which are typically much smaller. On the downside, dereferencing pointers has its own overhead, and managing the pointers can be complex. If you're dealing with small, simple objects and need fast, direct access, a regular array might be more efficient.

What are the risks associated with using arrays of pointers?

Arrays of pointers introduce a level of indirection, which, while powerful, can also be risky. Uninitialized pointers can lead to undefined behavior. Also, if you're not careful with memory management, especially in languages like C and C++, you risk memory leaks or double freeing, both of which can result in crashes or bugs. You have to be quite meticulous in managing both the array and the memory to which each pointer points.

{"pageComponentDataId":"c6016cday5451-43d6-9d34-e558a08d2b76","pageComponentId":"c6016cday5451-43d6-9d34-e558a08d2b76","pageComponentDataLangCode":"en","configData":{"jumpType":"currentTab","headlineColor":"black","displayNumber":"","styleMode":"vertical","headline":"","products":[{"number":{"t_id":"4XD1C99223","language":{"fr_ca":"","en_ca":"4XD1C99223","en_us":"","en":"4XD1C99223","fr":""},"id":"Paged364d785-5b43-46f3-897f-cfc1f2886cc5"}},{"number":{"t_id":"GX30Z21568","language":{"fr_ca":"","en_ca":"GX30Z21568","en_us":"","en":"GX30Z21568","fr":""},"id":"Page8a92c658-e187-4221-a70b-abfeb5c40052"}},{"number":{"t_id":"GX41L44752","language":{"fr_ca":"","en_ca":"GX41L44752","en_us":"","en":"GX41L44752","fr":""},"id":"Page3c3ca4cb-191e-42d6-b6bf-2a17188dcd34"}},{"number":{"t_id":"GY51F14319","language":{"fr_ca":"","en_ca":"GY51F14319","en_us":"","en":"GY51F14319","fr":""},"id":"Page9aad6b00-44a5-4f35-91db-6509e57b5f2f"}},{"number":{"t_id":"4Z91K18761","language":{"fr_ca":"","en_ca":"4Z91K18761","en_us":"","en":"4Z91K18761","fr":""},"id":"Page8d533231-87a4-40f2-9a1c-5e922f32affc"}}]},"urlPrefix":"AAAAAAAF","title":"glossary-right-blue-boxes-fragment","pageId":"e60a662e-c1b6-4ba3-afa9-6f6977b562f8","urlEdit":0,"uri":"/FragmentDirectory/gloccery/glossary-right-blue-boxes-fragment.frag","pageComponentUuid":"c6016cday5451-43d6-9d34-e558a08d2b76"}
coming coming
Starting at
List Price
Est Value
Est Value:
List Price
Est Value (Estimated Value)
List Price is Lenovo’s estimate of product value based on the industry data, including the prices at which first and third-party retailers and etailers have offered or valued the same or comparable products. Third-party reseller data may not be based on actual sales.
Estimated value is Lenovo’s estimate of product value based on industry data, including the prices at which Lenovo and/or third-party retailers and e-tailers have offered or valued the same or comparable products. Third-party data may not be based on actual sales.
Learn More
See More
See Less
View {0} Model
View {0} Models
Delivery options for {0}
Part Number
Features
See More
See Less
Compare
Added!
Great choice!
You may compare up to 4 products per product category (laptops, desktops, etc). Please de-select one to add another.
View Your Comparisons
Add To Cart
Add To Cart
We're sorry,
Products are temporarily unavailable.
Continue Shopping
Learn More
Coming Soon
Featured Product
Featured Products
Oops! No results found. Visit the categories above to find your product.
Save

Seasonal Sales & FAQ's

open in new tab
© 2024 Lenovo. All rights reserved.
© {year} Lenovo. All rights reserved.
Compare  ()
x