Write a C program for Variable with Pointer.

Function Main
Declare variables i, j as integers
Declare variable k as a pointer to integer

Read values for i and j from input

Print the values of i and j

If i is equal to 1 and j is equal to 2, then
    Print the product of i and j
Else
    Print the sum of i and j

Print the value pointed to by k (which is the value of j)

End

#include <stdio.h>
int main() {
//!showMemory()
  int i,j, *k= &j;
 
  scanf("%d%d", &i,&j);
  printf("i = %i, j = %i\n", i, j);
  if(i==1&&j==2)
  {
    printf("%d\n", i*j);
  }
  else{
  printf("%d\n",i+j);}
  printf("%d  //the values of Address of j",*k); //print the values of Address of j
}

1 2                                                                             
i = 1, j = 2                                                                    
2                                                                               
2  //the values of Address of j    

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.