Explain the ways of initializing the arrays, C/C++ Programming

Assignment Help:

Various ways of initializing the Arrays.

- The for loop initializes 10 elements with the value of their index.

 

   void main()

    {

                const int size = 10; 

                int arr[size];

 

for(int i = 0; i < size ; i++ ) // You can declare a

                variable here in C++.

                  {

                       arr[i] = i;

                   }

      }                      

 

  • An array can be explicitly initialized as follows.

e.g.

                int arr[3] = {0,1,2};

- An explicitly initialized array need not specify size but if specified the number of elements provided must not exceed the size. If the size is given and some elements are not explicitly initialized they are set to zero

                e.g.

 

                int arr[] = {0,1,2};

 

     int arr1[5] = {0,1,2}; // Initialized as {0,1,2,0,0}

      const char a_arr1[] = {'c'.'+','+'}          //size = 3;

 

                     const char a_arr2[] = {"c++"}  //size = 4 because of 

                                            null character at the 

                                                                 end of  the string;

  const char a_arr3[6] = "Daniel"; // ERROR; Daniel has 7  elements

 


Related Discussions:- Explain the ways of initializing the arrays

I need whatsapp software in my website, I need whatsapp software in my webs...

I need whatsapp software in my website Project Description: i need whatsapp software in my website same this whatsapp if anyone can make to me this in my website Skills

Define the float data type of c language, Define the Float Data Type of c L...

Define the Float Data Type of c Language? The float is used to define floating point numbers. The Floating point numbers are stored in 32 bits with 6 digits of precision. Eg

Recursion, #questiowrite a program to calculate e^x

#questiowrite a program to calculate e^x

Program that implements inference given a bayesian network, In this problem...

In this problem, you will write a program that implements two algorithms for performing exact inference given a Bayesian network, namely, enumeration and variable elimination. Your

[email protected], Write a program to find the area under the curve y =...

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

Age guessing game, Write a program that predicts users’ age (0-128 years ol...

Write a program that predicts users’ age (0-128 years old) with at most 7 questions. The game starts with asking the user whether he/she is younger or older than G (an initial gues

Explain logical operators, Logical Operators We say any expression that...

Logical Operators We say any expression that evaluates to zero is a FALSE logic condition and that evaluating to non-zero value is a TRUE condition. Logical operators are usefu

Day calculate b/w two dates, Write a function that calculates the number of...

Write a function that calculates the number of elapsed days between two dates. For example the days between Feb 3, 1970 and June 21, 1980? Becareful for the Leap year.

Inside and outside type casting, depth description of the inside and outsid...

depth description of the inside and outside typecasting

Standard input- output using motorola and intel devices, Talking to IO boar...

Talking to IO boards inside a computer or microcontroller depends upon the principles used by the microprocessor to address physical devices. On Motorola systems all devices connec

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd