473,503 Members | 1,849 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to find memory content at location x?

I'm reading a book that lists the example:

char month[10] = "January";

Memory for this looks something like the following:

| J | a | n | u | a | r | y | \0 | ? | ? |

Q1: How can I find out what is in the two memory locations following
the string terminator?
Q2: Does gcc zero out unused array elements?
Q3: If yes to Q2, where would I find that information?

Thanks!

Jul 18 '06 #1
6 1814
hu************@yahoo.com writes:
I'm reading a book that lists the example:

char month[10] = "January";

Memory for this looks something like the following:

| J | a | n | u | a | r | y | \0 | ? | ? |

Q1: How can I find out what is in the two memory locations following
the string terminator?
They're set to 0.
Q2: Does gcc zero out unused array elements?
Yes. The language standard requires it.
Q3: If yes to Q2, where would I find that information?
C99 6.7.8, para 21:

If there are fewer initializers in a brace-enclosed list
than there are elements or members of an aggregate, or fewer
characters in a string literal used to initialize an array
of known size than there are elements in the array, the
remainder of the aggregate shall be initialized implicitly
the same as objects that have static storage duration.
--
"I don't have C&V for that handy, but I've got Dan Pop."
--E. Gibbons
Jul 18 '06 #2
In article <87************@benpfaff.org>,
Ben Pfaff <bl*@cs.stanford.eduwrote:
>C99 6.7.8, para 21:
If there are fewer initializers in a brace-enclosed list
than there are elements or members of an aggregate, or fewer
characters in a string literal used to initialize an array
of known size than there are elements in the array, the
remainder of the aggregate shall be initialized implicitly
the same as objects that have static storage duration.
The C89 wording does not have the phrase about characters
in a string literal, but the "intended" behaviour can be deduced
by the example saying that initialization with a string
"is identical to" initialization with the brace-enclosed list
of characters, together with the explicit phrasing about fewer
initializers.

But on the surface, the C89 wording would appear to allow for a
difference between

char month[10] = { "January" };
and
char month[10] = "January";

in that the former is certainly a "brace enclosed list" but the later
is not -- the C89 part about the braces being optional for string
literals does not preclude the possibility of different behaviours
when the braces are or are not present.
--
All is vanity. -- Ecclesiastes
Jul 18 '06 #3
Ben Pfaff (in 87************@benpfaff.org) said:

| "I don't have C&V for that handy, but I've got Dan Pop."
| --E. Gibbons

Speaking of whom, where is Dan these days?

And while I'm asking OT questions, are you still at the same west
coast institution and do you still find time to make steel sing and
dance?

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto
Jul 18 '06 #4
hu************@yahoo.com wrote:
I'm reading a book that lists the example:

char month[10] = "January";

Memory for this looks something like the following:

| J | a | n | u | a | r | y | \0 | ? | ? |

Q1: How can I find out what is in the two memory locations following
the string terminator?
Q2: Does gcc zero out unused array elements?
Q3: If yes to Q2, where would I find that information?
Thanks for the answers. Now for two more related questions. I put in a
for loop to print the cell contents:

printf("Month: %s\n", month);
for (cell=0;cell<10;cell++)
{
printf("Cell %d: %c\n",cell+1,month[cell]);
}

Q4: How can I get the hex contents of each cell?
Q5: How can I format "printf("Cell %d: %c\n",cell+1,month[cell]);" so
I can get:
....
Cell 9 ... // Note: There are two spaces before the '9'.
Cell 10 ... // Note: There is one space before the "10".

Thanks!

Jul 18 '06 #5
In article <11**********************@p79g2000cwp.googlegroups .com>,
<hu************@yahoo.comwrote:
>I put in a
for loop to print the cell contents:
printf("Month: %s\n", month);
for (cell=0;cell<10;cell++)
{
printf("Cell %d: %c\n",cell+1,month[cell]);
}
>Q4: How can I get the hex contents of each cell?
Each cell only has value contents, and values are abstract. But you
can ask to have those values represented in hex:

printf("Cell %d: %c(%x)\n", cell+1,month[cell],(unsigned int)month[cell] );
>Q5: How can I format "printf("Cell %d: %c\n",cell+1,month[cell]);" so
I can get:
>Cell 9 ... // Note: There are two spaces before the '9'.
Cell 10 ... // Note: There is one space before the "10".
%2d instead of %d
--
There are some ideas so wrong that only a very intelligent person
could believe in them. -- George Orwell
Jul 18 '06 #6
I put in a
for loop to print the cell contents:
printf("Month: %s\n", month);
for (cell=0;cell<10;cell++)
{
printf("Cell %d: %c\n",cell+1,month[cell]);
}
Q4: How can I get the hex contents of each cell?

Each cell only has value contents, and values are abstract. But you
can ask to have those values represented in hex:

printf("Cell %d: %c(%x)\n", cell+1,month[cell],(unsigned int)month[cell] );
Q5: How can I format "printf("Cell %d: %c\n",cell+1,month[cell]);" so
I can get:
Cell 9 ... // Note: There are two spaces before the '9'.
Cell 10 ... // Note: There is one space before the "10".

%2d instead of %d
That was pretty cool. Thanks!

Jul 18 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6872
by: shyamal | last post by:
I want to display memory content using C++ on LINUX. For example, the user may ask to display 256 bytes from 0x1000ff00. The problem is , if any location is invalid, the program will coredump...
1
13648
by: Harsha | last post by:
I have been working on VB, ASP for quite a long time. Very Recently ( From past 1 month) I am managing a VC++ project. I am trying to use the code which i downloaded from the internet to find the...
11
1564
by: TIM | last post by:
for example i have one simple programm int main() { int test = NULL; while(1){ printf("%d\n",test); getch(); test++; }
20
3032
by: Jonas | last post by:
Hi, I'm 99 % sure that Standard C guarantees to do a memory move inside realloc() in case the new, returned memory block (address) is different than the original one. Can any C expert confirm...
1
1553
by: Tosch | last post by:
I have an application that uses to COM objects and does a complex file conversion between two different systems. When converting a large amout of files I'm experiencing a memory leak resulting in...
16
9500
by: Otie | last post by:
Hi, Is there a way for VB5 to determine exactly where on a hard drive a .exe file is stored upon the .exe file's first copying to the hard drive? What I need to know is the exact hard drive...
7
7189
by: yancheng.cheok | last post by:
hello all, in my memory content says, 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8 ... 0xff i wish to shift it n bits. please note that, not n bye, but n bit, and n can be any value 0, 1,...
0
1260
by: wizofaus | last post by:
If you use your browser to navigate to http://www.fsa.gov.uk/register/, it will redirect you to http://www.fsa.gov.uk/register/home.do;jessionid= etc. etc. etc. But if you use WebRequest to fetch...
1
1234
by: Amol J Kothawade | last post by:
Hi, I want to release memory consumed by database. I used datagridview in my windows form and provided dataset for database. after closing that application i find that it allocate the memory for...
0
7093
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
7287
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
7348
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...
1
7006
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
5592
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,...
0
4685
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.