Using a Pointer and Displaying the Address

Here is the output from the code below:
1
1

I can't figure out how to display the memory address.

//---------------------------------------------------------------------------

#include "mariamole_auto_generated.h"

//---------------------------------------------------------------------------

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
  http://arduino.cc
  This example code is in the public domain.
  modified 8 May 2014
  by Scott Fitzgerald
 */
 


// the setup function runs once when you press reset or power the board

void setup() {
Serial.begin(9600);
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
 
}

// the loop function runs over and over again forever
void loop()
{
int teeny;
int *t;
teeny = 1;
t = &teeny;

Serial.println(teeny);
Serial.println(t);
Serial.println(*t);
Serial.println("----");



  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
	
}

The error is, "Pointer_1.cpp (36): call of overloaded 'println(int*&)' is ambiguous"
The output is:
Detecting undeclared functions in main project file: Pointer_1.cpp...
Compiling file: /Pointer_1/source/Pointer_1.cpp

C:/Program Files (x86)/MariaMole Beta/arduino/hardware/tools/avr/bin/avr-g++ -c /Pointer_1/source/Pointer_1.cpp -o /Pointer_1/build/source_Pointer_1.cpp.o -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -MMD -DARDUINO=105 -mmcu=atmega328p -DF_CPU=16000000L -I /Pointer_1/source -I C:/Program Files (x86)/MariaMole Beta/arduino/hardware/arduino/cores/arduino -I C:/Program Files (x86)/MariaMole Beta/arduino/hardware/arduino/variants/standard
/Pointer_1/source/Pointer_1.cpp: In function 'void loop()':
/Pointer_1/source/Pointer_1.cpp:36: error: call of overloaded 'println(int*&)' is ambiguous
C:/Program Files (x86)/MariaMole Beta/arduino/hardware/arduino/cores/arduino/Print.h:70: note: candidates are: size_t Print::println(char)
C:/Program Files (x86)/MariaMole Beta/arduino/hardware/arduino/cores/arduino/Print.h:71: note: size_t Print::println(unsigned char, int)
C:/Program Files (x86)/MariaMole Beta/arduino/hardware/arduino/cores/arduino/Print.h:72: note: size_t Print::println(int, int)
C:/Program Files (x86)/MariaMole Beta/arduino/hardware/arduino/cores/arduino/Print.h:73: note: size_t Print::println(unsigned int, int)
C:/Program Files (x86)/MariaMole Beta/arduino/hardware/arduino/cores/arduino/Print.h:74: note: size_t Print::println(long int, int)
C:/Program Files (x86)/MariaMole Beta/arduino/hardware/arduino/cores/arduino/Print.h:75: note: size_t Print::println(long unsigned int, int)

Cast it to "unsigned int" or "unsigned long"

Through viewing a post by mellis I was able to display a memory address.

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the Uno and
  Leonardo, it is attached to digital pin 13. If you're unsure what
  pin the on-board LED is connected to on your Arduino model, check
  the documentation at http://arduino.cc

  This example code is in the public domain.

  modified 8 May 2014
  by Scott Fitzgerald
http://www.tutorialspoint.com/cprogramming/c_passing_pointers_to_functions.htm  
  
 */
 
 void setup()
 {
   Serial.begin(9600);
   
   //void getSeconds(unsigned long *par);  This declaration not necessary.  
 }
 
 void loop()
 {
   unsigned long seconds = 0;
   
   
   Serial.println("-------");
   Serial.print("seconds before function: ");
   Serial.println(seconds);
   Serial.print("Address of seconds: ");
   Serial.println((long)&seconds);//This is where I trouble displaying the memory address.
   
   
   
   
   getSeconds( &seconds); //
   Serial.print("seconds after function: ");
   Serial.println(seconds);// Through the pointer and function, the value at the address of seconds equals *par.
 }
//-------
void getSeconds(unsigned long *par)//Take what in the address of seconds (&seconds) and put that value in address of *par.
{
  Serial.print("Address of *par: ");
  Serial.println((long)&par);
  Serial.print("*par first: ");
  Serial.println(*par);
  *par = millis();//Make the value at the address at *par equal to millis().
  Serial.print("*par after millis: ");
  Serial.println(*par);
  delay(1000);
}
   

/*
// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}
*/
Serial.println((long)&seconds);

AWOL:
Cast it to "unsigned int" or "unsigned long"

1 Like