473,657 Members | 2,524 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 1827
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.stanfor d.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,mo nth[cell]);
}

Q4: How can I get the hex contents of each cell?
Q5: How can I format "printf("Ce ll %d: %c\n",cell+1,mo nth[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************ **********@p79g 2000cwp.googleg roups.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,mo nth[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("Ce ll %d: %c\n",cell+1,mo nth[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,mo nth[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("Ce ll %d: %c\n",cell+1,mo nth[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
6888
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 because of attempt to access invalid memory.I understand that in Windows OS there is a function that tells if a memory location is valid or invalid. Is there a similar function in Linux? How does gdb display memory content? I will appreciate a...
1
13665
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 memory leak in the VC++ dll which is causing the servers to crash. I am getting the compilation error on this particular line void * __cdecl operator new(unsigned int size,const char *file, int line) error C2059: syntax error : 'string'
11
1580
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
3053
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 this to me, please? Thanks, Jonas PS. I using C90, not C99--if it makes a difference.
1
1564
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 my application eating hundreds of MBs of memory and not releasing it. This again results in a system being very unstable and my application finally crashing. What is the best way to figure out which component is eating up the memory? I have...
16
9518
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 sector, cluster, partition, etc. information so I can use it later on to determine if the file was ever deleted and restored or moved elsewhere. Thank you.
7
7210
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, 2...... let's say n = 8,
0
1266
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 that initial URL, the response URL is "http://xdsapvip:3006/register/WEB-INF/jsp/layouts/base.jsp"! This is actually the content of the HTTP "content-location" header, which as I understand it, is only for identification of where as resource came...
1
1243
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 database. I want to find memory release method in VB.Net
0
8324
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8617
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7352
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5642
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2742
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 we have to send another system
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.