What is wrong in this c++ code?

Posted by narayanpatra on Stack Overflow See other posts from Stack Overflow or by narayanpatra
Published on 2014-08-19T16:13:16Z Indexed on 2014/08/19 16:20 UTC
Read the original article Hit count: 142

Filed under:
|
|

Why this coder do not show error

#include <iostream>

int main()

{
  using namespace std;
  unsigned short int myInt = 99;
  unsigned short int * pMark = 0;
  cout << myInt << endl;
  pMark = &myInt;
  *pMark = 11;
  cout << "*pMark:\t" << *pMark << "\nmyInt:\t" << myInt << endl;
return 0;
}

But this one shows :

#include<iostream>
using namespace std;

int addnumber(int *p, int *q){

    cout << *p = 12  << endl;
    cout << *q  = 14 << endl;


}

#include<iostream>
using namespace std;

int addnumber(int *p, int *q){

    cout << *p = 12  << endl;
    cout << *q  = 14 << endl;


}

int main()
{
  int i , j;
  cout << "enter the value of first number";
  cin >> i;
  cout << "enter the value of second number";
  cin >> j;
  addnumber(&i, &j);
  cout << i << endl;
  cout << j << endl;
}

In both the code snippets, I am assigning *pointer=somevalue. In first code it do not show any error but it shows error in the line

cout << *p = 12  << endl;
cout << *q  = 14 << endl;   

What mistake I am doing ?

© Stack Overflow or respective owner

Related posts about c++

Related posts about function