1
#include <iostream>
using namespace std;
int main(){
    int a=985;
    cout << a;
}

Second is

#include <iostream>
using namespace std;
int main(){
    int a(985);
    cout << a;
}

Hi What is difference between int a(985) and int a=985. Mean any logic between these methods of value assignment? Same for char and string etc..

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
Asif Mushtaq
  • 3,658
  • 4
  • 44
  • 80

1 Answers1

2

There is no difference. Both

T t = to;

and

T t (to);

for some other T to copy constructs t from to. If to and t have different types, things get more complicated, e.g. see here.

Community
  • 1
  • 1
Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182
  • sorry little confused you mean a(985) 985 is copying to a? – Asif Mushtaq May 02 '15 at 17:00
  • @AsifMushtaq Basically yes. For value-like types like `int` both will set the LHS to the value of the RHS. For more complex types, both will still do the same if the LHS and the RHS have the same type, just probably something more complex. – Baum mit Augen May 02 '15 at 17:02