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

How to estimate the sizeof(ptr) and izeof(*ptr)

#include <stdio.h>
int main()
{
int arr[2][2];
int *p[2];
int (*p1)[2];
p[2]=arr[2];
p1=&arr[2];
printf("size of p is %d\t, *p is %d\n",sizeof(p),sizeof(*p));
printf("size of p1 is %d\t, *p1 is %d\n",sizeof(p1),sizeof(*p1));
}
Output:
size of p is 8 , *p is 4
size of p1 is 4 , *p1 is 8
Please tell me how to actually relate my code to this output!
Aug 6 '14 #1

✓ answered by weaknessforcats

Expand|Select|Wrap|Line Numbers
  1. p[2] = arr[2];
Before getting too far into this code, the program crashes here because p is an array of 2 pointers to int. So there is a p[0] and a p[1] but p[2] references memory outside the array, corrupts it and causes a crash on my machine.

You may want to read this: http://bytes.com/topic/c/insights/77...rrays-revealed

1 1127
weaknessforcats
9,208 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. p[2] = arr[2];
Before getting too far into this code, the program crashes here because p is an array of 2 pointers to int. So there is a p[0] and a p[1] but p[2] references memory outside the array, corrupts it and causes a crash on my machine.

You may want to read this: http://bytes.com/topic/c/insights/77...rrays-revealed
Aug 7 '14 #2

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

Similar topics

6
by: Steve Z | last post by:
I know this isn't a code question, but could use some help. What would a fair estimate be for the total manhours needed for a non-certified person to develop a VB interface to an Access db with...
8
by: Mav | last post by:
Hi, all I wonder is that any way to estimate the build time from VS.net(C++ project). We have a lot of projects(40) under one single solution. We use the command line (devenv.exe...
6
by: Tony | last post by:
I would like a cost estimate for the development of an small application that : 1. Scans email inbox, for messages with the subject "QSData" (or title read from ini file) 2. Reads the...
4
by: Fan Ruo Xin | last post by:
How to estimate the size of log space when I need to run "INSERT INTO tgt_tbl SELECT * FROM src_tbl WHERE..." ? What is the difference of before image between the above INSERT stmt and the...
1
by: Thomas Wang | last post by:
How I can estimate null reference of an object without fire NullReferenceException ? (for example: estimate ListBox.datasource is null or empty) B.Rgds
31
by: Bob | last post by:
I have recently joined a healthcare company where I am the solo programmer. I am going to be starting work on a project. The management has asked me to provide an estimate of hours I am going to...
9
by: shuisheng | last post by:
Dear All, I have little experience in coding. For a c++ code with 30,000 lines, It is large or small? For two average programmers, usually how long does it take to finish the code? The code...
4
by: Alvin SIU | last post by:
Hi all, I am now doing development using DB2. Q1. There is one tablespace to store 5 tables. But, when in production, there will be one tablespace for EACH of the tables.
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.