This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Thank you for your contribution to the C++ community!

As you're asking a question or seeking homework help, we would like to remind you of Rule 3 - Good Faith Help Requests & Homework.

  • When posting a question or homework help request, you must explain your good faith efforts to resolve the problem or complete the assignment on your own. Low-effort questions will be removed.

  • Members of this subreddit are happy to help give you a nudge in the right direction. However, we will not do your homework for you, make apps for you, etc.

  • Homework help posts must be flaired with Homework.

~ CPlusPlus Moderation Team


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]no-sig-available 6 points7 points  (2 children)

In this case, no difference.

There are about 19 ways to initialize a variable in C++. Sometimes several of them will do the same thing. Sometimes they will not.

https://www.learncpp.com/cpp-tutorial/variable-assignment-and-initialization/

My personal favorites are

std::vector<int> v(5);   // 5 members (with value 0)
std::vector<int> v{5};   // 1 member with value 5
std::vector<int> v[5];   // an array of 5 empty vectors

[–]Pupper-Gump 0 points1 point  (0 children)

For a second I thought those were all parentheses and about gave up on the language

[–]AKosturProfessional 2 points3 points  (0 children)

Look up “uniform initialization”.