4 Replies - 518 Views - Last Post: 16 April 2012 - 04:04 AM Rate Topic: -----

#1 Nation_programmer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 14-April 12

Function to see the memory in C programming in VS 2010

Posted 15 April 2012 - 10:01 PM

#include<stdio.h>
#include<Windows.h>
main()
{
	char ch;
	system("cls");
	ch='A';
	printf("Value of %c is %d",ch,ch);
	ch=ch+1;
	printf("\n Value of ch is increased by 1");
	printf("\n Value of %c is %d",ch,ch);
	getchar();
}


Above Code is an example of C programming in Visual Studio 2010.

Question

My question is---If I want to see which data stored in which bit of memory and when it will be saved in memory what will be its form means in the case of above example how will be saved 'A' in memory and if I use '1' instead of 'A' then how will be saved in memory?

I need something by which when I shall use printf function I can see the form of stored data in memory in which bit and how.

If any one knows then make me understand this matter step by step to know that I am using Visual Studio 2010.I do not know that I can make you understand my problem or not.

Is This A Good Question/Topic? 0
  • +

Replies To: Function to see the memory in C programming in VS 2010

#2 turboscrew  Icon User is offline

  • D.I.C Addict

Reputation: 100
  • View blog
  • Posts: 615
  • Joined: 03-April 12

Re: Function to see the memory in C programming in VS 2010

Posted 15 April 2012 - 10:52 PM

It IS hard to understand your problem.

Do you want to write out (dump) the memory bytes, or do you wonder how
characters are stored, or what?

In the example "A" is stored as ASCII-code ('A'=65) in the constant storage part of the data section memory of the program from where it is copied into the address "allocated" for variable "ch" in "ch='A';".

The data section stuff is created by the compiler and re-arranged by the linker.
Was This Post Helpful? 0
  • +
  • -

#3 turboscrew  Icon User is offline

  • D.I.C Addict

Reputation: 100
  • View blog
  • Posts: 615
  • Joined: 03-April 12

Re: Function to see the memory in C programming in VS 2010

Posted 15 April 2012 - 11:19 PM

Oops, sorry, single-value constants (chars, ints doubles) are typically not stored anywhere special, but just put there in the code as immediate operand(s) of some assembly instruction(s), unless the constant is a variable initialiser, in which case "cinit" (C runtime environment initialiser) copies it to the initialised variable.

Constant strings, arrays and such go to the data section.
Was This Post Helpful? 0
  • +
  • -

#4 Nation_programmer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 14-April 12

Re: Function to see the memory in C programming in VS 2010

Posted 16 April 2012 - 03:30 AM

Above mentioned code was an example.Just think in the case of character variable I used char ch; ch='A' or '1',in the case of integer variable I used int i;i=45 etc.Then is there any program or code in c language by which I can see the memory completely and inside the memory in which bit stored which value?

We know for int type variable C takes 2 byte=16 bits.And the 1st bit number of 16 bits will be zero and last 1 will be number 15 which is for + or -.So,in the case of 1,computer will store in memory the binary value of 1 from bit zero to 15 and number 16 will be + or -.

So,I want to see the every bit of memory where in which area which binary has been stored for the above mentioed example.So,if any 1 knows any program or code by which I can see the memory completely In the case of above example not only above example in every example I can see then say.

I hope now that I could make you understand my problem.
Was This Post Helpful? 0
  • +
  • -

#5 turboscrew  Icon User is offline

  • D.I.C Addict

Reputation: 100
  • View blog
  • Posts: 615
  • Joined: 03-April 12

Re: Function to see the memory in C programming in VS 2010

Posted 16 April 2012 - 04:04 AM

Those things are separate programs called "debuggers". Those can typically dump the memory. Some even have the "search" function.

If you are using a PC, you might have a bit of work there if you list, say, 1G of memory
(that is 1024x1024x1024 bytes = 1073741824 bytes.

(BTW at least PCs use 32-bit integers)

Another thing you could do:

char * chp;

// Now chp contains the address of the variable ch - if you
// want to dump it with a debugger
chp = &ch

// To print out the address "%p" means "natural pointer format"
printf("%p\n", chp);

// To print the bytevalue out as hex (no binary - sorry)
printf("0x%2X\n", (int) ch);

Still got it wrong?

This post has been edited by turboscrew: 16 April 2012 - 04:09 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1