how can i store which button was pressed last time among many...

i am not having any code .. i just want to know is there any program to store which button was pressed among three to four buttons last time..if electricity is gone even then my program should know which button was pressed earlier and execute that function or loop.

You could store the button press in EEPROM. Take a look at the example sketches in the IDE under ">File >Examples >EEPROM"

Store it in the on-chip EEPROM:

I would caution you however to be careful with your programming. A given address within the EEPROM can only be written to 100,000 times. That's a whole lot of button pushes, if programmed correctly.

However, if programmed wrong, those 100,000 cycles can be burned up in a matter of minutes. Assuming you have a variable Holding the button press you just read (currentButton) and another holding the last button pressed (lastButton) then never write to EEPROM if currentButton = 0 (no button pressed) and also never write to EEPROM if currentButton = lastButton.

Take those precautions and all will be well for a long, long time.

If you want to write to EEPROM often (every second recording the temperature for example) then you should consider using a separate SD Card rather than the EEPROM on the ATMEGA (Arduino) chip. First off, assuming you write to a file, there is circuitry built into the SD Card to spread use around and secondly, you can replace the SD Card really easy and don't Need to reprogram the Arduino.

so if i used two push button for on and off led i am making the light on...if electricity goes out....light will be off...and when electricity comes led should be on automatically....
how to overcome this electricity problem

After a certain number of writes, shift the storage position up in EEPROM 'til you get to the top, then rotate back to the bottom.

can i store button pin number and its state also....? if yes then HOW....?

Write some code and test it.

You don't need the pin number in eeprom for this; your code should know that the first bit (or byte) in the eeprom belongs to a certain pin, the second one to another pin and so on.

The eeprom.put() function will only write to eeprom if the value that you are writing did change prolonging the life of the specific cell.

then which function should i use… (eeprom write and read) or (eeprom put and read)

if i am writing this simple sketch …how can i implement them in this one

int x;
const int buttonPin[] = {2, 3};    // the number of the pushbutton pins
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {

  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  for ( x = 0; x < 2; x++)
    pinMode(buttonPin[x], INPUT);

void loop() {
  // read the state of the pushbutton value:

  for ( x = 0; x < 2; x++)
    buttonState = digitalRead(buttonPin[x]);
    if (buttonState == 0 && buttonPin[x] == 3)
      // turn LED on:
      digitalWrite(ledPin, HIGH);
    if (buttonState == 0 && buttonPin[x] == 2)
      // turn LED off:
      digitalWrite(ledPin, LOW);