473,402 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

pointer to an array

main()
{
int a[4][4];

int *q[4]; // now q points to an array of 4 integers;

now if i want to access array elements through this pointer q, what should i do?

/*
q=a;
ans=*(q);
/* this lines are producing garbage values on console!
don knw y?
}
Dec 25 '11 #1
2 1191
johny10151981
1,059 1GB
please define q as
Expand|Select|Wrap|Line Numbers
  1. int **q;
Dec 25 '11 #2
weaknessforcats
9,208 Expert Mod 8TB
Please read this: http://bytes.com/topic/c/insights/77...rrays-revealed


Ths is not true:
Expand|Select|Wrap|Line Numbers
  1. int *q[4]; // now q points to an array of 4 integers;
  2.  
q is an array of 4 pointers to int.

A pointer to an array of 4 ints would be:


Expand|Select|Wrap|Line Numbers
  1. int (*q)[4];
  2.  
q[0] is the first array of 4 int and q[0][1] is the 2nd int in the q[0] array.

Expand|Select|Wrap|Line Numbers
  1. int** q;
cannot be used as a pointer to an array because it is a pointer to a pointer to a single int.

I have seen this used as a pointer to a 2d array but not without typecasting and a bunch of other fiddling to keep the compiler happy.
Dec 25 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Bryan Parkoff | last post by:
I want to allocate pointer array into memory so pointer array contains ten pointers. It would be 4 bytes per pointer to be total 40 bytes. Looks like below for example. unsigned char* A = new...
5
by: Brett | last post by:
Sorry for the rookie question.... If I have a pointer array (for example): char *colors = { "blue", "green" }; and I want to add yellow to this array later in my code....how would I do
2
by: Min-su KIM | last post by:
HI~ I need to access the pointer array via DLL. Original C code is char * buf; for (int i = 0; i < 63; i++) { buf = new char ; } API_CALL(buf);
2
by: Potiuper | last post by:
Question: Is it possible to use a char pointer array ( char *<name> ) to read an array of strings from a file in C? Given: code is written in ANSI C; I know the exact nature of the strings to be...
1
by: nozone | last post by:
Hi. I am new to the C language. I need to store the commands from input to a pointer array without any ""declaration. How to create an pointer array by memory allocation? I tried to use the following...
1
by: MyCGal | last post by:
Hi, I have this code I wrote to copy any length lines into array of pointers. The problem is after storing the individual lines into the char pointer array, the dispaly() chops off some lines...
5
Nosnibor
by: Nosnibor | last post by:
Need some direction as how to implement a pointer array which will mimic a 2D array. Any suggestions? This is where I am. Do not work, but i am working on it. Please send suggestions. I think my...
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
5
by: Immortal Nephi | last post by:
I would like to design an object using class. How can this class contain 10 member functions. Put 10 member functions into member function pointer array. One member function uses switch to call...
13
by: pereges | last post by:
Hi, can some one please tell me why this program is not able to function properly. I have a array a and i am trying to create a pointer array b which points to elements less than 40 in a. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.