473,385 Members | 1,324 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,385 software developers and data experts.

Correct the memory alloc for int (*q)[10];

Yours valuable suggestion would help me.
OS used - Linux Compiler used - gcc

1) How can the memory for the pointer "q" be created using malloc.
where q is "int (*q)[10];" ?

When I tried with
Expand|Select|Wrap|Line Numbers
  1. q = (int *) malloc(sizeof(int)*10);
getting an error ( it is a warning)
"warning: assignment from incompatible pointer type"



2) What is the differnce between the pointer q from p
Expand|Select|Wrap|Line Numbers
  1. int *p;
  2. p = (int*) malloc(sizeof(int)*10);
May 20 '11 #1
3 2154
donbock
2,426 Expert 2GB
For a hint, allocate q statically and then print sizeof(q).

Can you describe in words what the type of q is?
May 20 '11 #2
In the above example p and q are similar type of pointers - pointer to an arry of int of size 10 nos. Correct ?

int (*q)[10];
q = (int *) malloc(sizeof(int)*10);
The above initialization and memory creation is incorrect?
May 23 '11 #3
Banfa
9,065 Expert Mod 8TB
Not correct look again at the point you declare p. Where in that does it indicate that it points to an array of 10 integers? It doesn't, it is just a pointer to an integer there is no size element involved in it's declaration.
May 23 '11 #4

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

Similar topics

6
by: B. Gandhi | last post by:
Hi friends I have a query regarding memory allocation deallocation in C. It is as follows: char *path = getenv("PATH"); In this call to getenv(), where does the returned string stored?...
6
by: Vulcan Fire | last post by:
Hi Why is that int *p = 12; core dumps & not char *p = "some_str";
10
by: Ryan Wang | last post by:
Hi, here is the function: int sum(int a,int b) { int c; c = a + b; return c; }
1
by: -DG- | last post by:
I'd like to find out more about what is implied when articles on mem-management refer to Generation 0 or 1. Any online references?
1
by: Bob | last post by:
Our production server has 2GB of RAM but aspnet_wp.exe only uses up to 150MB. The site gets pretty heavy traffic and I'm wondering if increasing the memory useage for aspnet_wp.exe would help the...
2
by: cnliou | last post by:
Linux 2.4.23 on AMD 450MHz. pgsql 7.4.1 configure --enable-multibyte=UNICODE locale is zh_TW.Big5 IIRC, when I did "initdb -E UNICODE" or "createdb db1", I saw the following message from...
1
by: John Hagstrand | last post by:
Hello, I'm getting the following error when I try to update or insert into a table. This just started happening today. The table has been working fine up to now. The table has 27,000 rows and...
5
by: Janning Vygen | last post by:
Hi, tonight my database got corruppted. before it worked fine. since two days i do the following tasks every night psql -c 'CLUSTER;' $DBNAME psql -c 'VACUUM FULL ANALYZE;' $DBNAME ...
0
by: craig.conboy | last post by:
Using MC++ .Net 2.0, with the CLR Profiler (from Microsoft) I am seeing that 3 blocks of memory, each ~48MB in size, being allocated by some code that initializes a managed array. It is a jagged...
1
by: crimsonalucard | last post by:
Below is a function I wrote used to evaluate the determinant of a nxn matrix. arguments are an array of the matrix values in order going from left to right jumping to the next line then going from...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.