How to declare and initialize an array in C++?

clock icon

asked 1 year ago Asked

message

2 Answers

eye

14 Views

 I'm new to C++ and want to understand how to declare and initialize arrays. Can someone provide a simple example of how to declare an array, assign values to it, and access its elements?

2 Answers

To declare an array in C++, you need to define

  • The data type of elements in the array
  • The name of the array
  • The size of the array

    Syntax:

              Data_type Array_Name [size];

Depicted below is an example of a declaration of the array.

Example:

                 int club[10];

Live Chat Widget
https://support.microsoft.com/en-us/home/livechatwidget?theme=smc_colorful&sourceapp=signup1&customcontext=%7B%22seats%22%3A%22-1%22%2C%22screen%22%3A%22ValidatePromoCode%3A%20undefined.undefined%22%2C%22market%22%3A%22US%22%2C%22product%22%3A%22Microsoft%20365%20Business%20Basic%20-%20Trial%22%2C%22productid%22%3A%22undefined%22%2C%22mode%22%3A%22AdminTrialWithPI%22%2C%22cartsid%22%3A%22081227f4-2d00-4678-a558-117e6ed9ee93%22%2C%22CaseNumber%22%3A%222412050010000021%22%7D

Write your answer here

Top Questions