473,385 Members | 1,901 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.

How to print the value at memory address?

I have written a C program without variable. And I want to print the value at that memory location.How to print that value?

code is like:-

Expand|Select|Wrap|Line Numbers
  1. int main()
  2.  {
  3.      printf("Enter value:");
  4.      scanf("%d",1245024);
  5.      /* how to print the value here */ 
  6.  
  7.  return 0;
  8.  }
Nov 20 '12 #1
8 15647
donbock
2,426 Expert 2GB
You want your program to read some arbitrary location that is outside the bounds of your program.

Doing so provokes implementation-defined behavior. Anything could happen, but the two most likely outcomes are a run-time error (typically a segment error) from trying to access an inaccessible memory location; or the memory location is successfully accessed.

Cast the address value into a pointer to the type corresponding to how you wish to access the location (that is, unsigned char* or unsigned short* or unsigned long* or ...). Then dereference the pointer and see what happens.
Nov 20 '12 #2
I want the answer without any variable not even pointer...
Nov 21 '12 #3
whodgson
542 512MB
Put the unsigned integer into the first element of an array and call printf on the array name. Also I don't think I have ever read (or heard)that a pointer could be classified as any form of variable.
Dec 14 '12 #4
Banfa
9,065 Expert Mod 8TB
Shubhangi24: donbock did not suggest using a variable, he suggested that you cast you integer constant to have a pointer type and then dereferenced it to get the value at that address something like *((unsigned char*)1) no variables involved and a well known technique for accessing registers on an embedded platform..

whodgson: your array thing wont owrk and uses a variable. Also pointers can't be variables??? Think about it, what do you think have if you declare something like char *p; as used by countless C library functions. p is a variable and it is a pointer.
Dec 14 '12 #5
whodgson
542 512MB
Here's what the inventor says about it:
"The places in which we store data are called objects. To access an object we need a name. A named object is called a variable and has a specific type... the data items we put into variables are called values. The statement that defines a variable is (unsurprisingly) called a definition"
Dec 15 '12 #6
whodgson
542 512MB
to Banfa: I agree having tried it that an array won't even work for me presumably because a variable needs a name before memory is allocated and it becomes an object.
But I can't see how a pointer is also a variable because i understood that a valid pointer only ever contains the address of whatever it currently points at (or to). Although this has no bearing on the argument i also thought that a pointer had to be initialized at the time it was declared.
Dec 16 '12 #7
donbock
2,426 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. int a = 10;
  2. int *b = &a;
a and b are variables.
The value of a is 10.
The value of b is the address of a. That is, b is a pointer to a.
Dec 16 '12 #8
whodgson
542 512MB
Yes...thanks, I've been back over it and what you both have said is what i have been reading. Some things just seem to go through to the keeper without registering.
Dec 17 '12 #9

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

Similar topics

4
by: | last post by:
Hi I have a list containing several instance address, for example: I'd like to invoke a method on each of these instance but I don't know : 1. if its possible 2. how to proceed
3
by: scott.lewis | last post by:
Hi, I'm developing in C++ using Visual Studio 7.1. Is there any way to get the memory address from a referenced parameter? In other words, can I find the pointer value as if it were passed in...
5
by: Jeong-Gun Lee | last post by:
I'm writing a code of writing a value to a specific memory address. ================================================================= #include <stdio.h> int main() { long air; long...
2
by: iwdu15 | last post by:
hi, how would i get the memory address of a said pointer in my program? thanks -- -iwdu15
12
by: FI | last post by:
Hello All, I am relatively new to C programming and I am struck with a problem in dynamic memory allocation. I would like to know if it is ok to pass the 'memory address' returned by...
20
by: sethukr | last post by:
hi, i need to store a value to a particular memory location without having a variable. So, how can i access a 'memory address' without using variables?? Is it possible in C??? Plz, help...
15
by: polas | last post by:
Hi everyone - I have a question. I am just playing around with C (I realise there are better ways to do what I want, but I would like to do it this way to increase my understanding of C) and would...
1
by: cman | last post by:
What is the effective behaviour if you cast a memory address? I have come across code where memory address 0 is cast to a 'struct foo' type. What does this amount to? Does address 0 now point to...
5
by: erfan | last post by:
vc++6.0,winxp. I use this code to see the memory address and the real value`s address below: #include<stdio.h> int main() { int a=22; int *p; int i; p=&a;
2
by: Ed | last post by:
Hi, guys, In Visual Studio C++ 2008, I can add an item "*(int*)0x00385fa0" in Watch window to catch the value in that memory address. The value evaluation is OK. The question is how can I know...
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: 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
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...
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
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...

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.