Detailed Overview of One-Dimensional Array of C Language [Tutorial]

One-Dimensional Array




                                                        1-Dimensional Array:                                                    


It is a linear list of fixed number of data items of the same type. All these data items are accessed using the same name using a single subscript. It is similar to a row or column matrix. It is also called as a single-dimensional Array or one subscripted variable.


                                                              Declaration:                                                             


The syntax of declaring a one-dimensional Array is as follows:


  data_type arrayname [size];  


where
arrayname => name of the Array.
size => number of elements of same data type.

Example:
  • double p[50];  
means p is an Array of 50 double precision numbers.
  • char name[20];
means name is an array of 20 character long.
  • int list[5];
means list is an Array of 5 integer constants.
  • float xyz[10];
means xyz is an Array of 10 floating-point numbers.


                                                         Total Size of 1-D Array:                                               


The total memory that can be allocated to one-dimensional Array is computed as:


  Total size = size * (size of (data_type));  


where
size => number of elememts in 1-D Array.
sizeof () => is an unary operator used to find the size in bytes.
data_type => basic data types such as int, float, char, double etc.

Example:
  • int A[10];
A is an Array of 10 integer constants. The total size of 1-D Array of 10 integers is 20 bytes because the size of an integer data is 2 bytes.



                                                       Initializing a 1-D Array:                                                 


Array-Initialization

Like initialization to ordinary variable, the individual elements of an Array can also be initialized. Initialization is nothing but assigning some value to the variable that undergoes processing. All the initialized values must be constants. But never be variables or function calls. Initialization can be made to all Array elements during the time of declaration. The Syntax for 1-D Array initialization is:


  data_type array_name[size] = { element1 , element2 , ..................elementn}; 


where
element1 , element2 .....elementn => are initialized(or initial) values enclosd with in a pair of curly braces {}. All these elements must be seprated by comma and these elements must be written in the order in which they will be assigned.

Example:
  • int EvenNum [4] = {2 , 4 , 6 , 8};
This declaration initializes the first 4 elements of an Array EvenNum by 4 even integers as shown


                                                           Points to Remember:                                                    
  • int num[3] = {2 , 4 , 5};
Till the Array elements are not given any specific values, they are supposed to contain garbage values.
  • int A[ ] = {1 , 2 , 3};
If the array is initialized where it is declared, mentioning the dimension of the Array is optional.
  • float xyz[6] = {8 , 24 , 36 , 50};
Since, there is no explicit value assigned to xyz[4] and xyz[5]. In such a case, they will automatically be set to zero.
  • char greeting[10] = "Hello";
String

Since, there is no explicit values assigned from greeting[5] and greeting[9]. In such a case, they will automatically be set to null symbol (\0).

                                                                  That's All

0 Response to "Detailed Overview of One-Dimensional Array of C Language [Tutorial]"

Post a Comment

Popular Posts

Label

1 Sidebar 2 Columns 3 Columns Footer 3rdball 4 Columns Footer Alex Alvaro Antsasia Arlinadesign Averie Barry BASIC CONCEPTS Basil Bayna Fast BeautyPress BeautyTemplates Beckel Best Best - Clean Beyonce Pro BioMag BlackMag Blanter Nova Blogger Card Bloggertheme9 Blogish Bpress Brakt C LANGUAGE C PROGRAMS C++ LANGUAGE C++ PROGRAMS Carella Cellar Charlotte Chooko Lite Clara Clean Combo One Cooperate Crusade Darry Dorman Dreamway Dunia Blanter eCars EduAcademy EducationPress Elise Elvan Eva Everyday FabNews Fashion Fashion Blogger Template Fashion Gossip FastCars Fedo FlashNews Fredy Portfolio Gaming Globus GoodTime Goomsite HTML LANGUAGE iGaming Indicate Innove Insomnia InspiredNews iSoft Jasmine Kalem Landscaping Lashira Lavelle Lily Fashion Limax Linea Lionex Luminescence Lite Lumix Luxury Magazine MagazinePro MAJOR DIFFERENCES MarketingBlog Martin MaxiMag Medica Mega Melissa Mercury MeshMag Minimag Minimalist MiniNews MovieKhor msdesignbd MusicLand Neko NetZine New Spread News16 Newsflash NewsForce NewsIdea Newspaper News NewsPro Nubie Fast Odd Themes Optima PaperMag PaperMag blog Parhlo Perfection Personal Personal Blog Photosout PixelZ Power Blog Premium Themes ProfileMag Purez Rano ReadNews Real estate Remito Grid Responsive Revo Robusta Rotario Saara SeoBoost Settle Shouters Simple Catch SimpleClean Sketchly SNews SolidMag Someo Sophie Sora Sora Bank Sora Home Sora News Responsive Sora One Sora Ribbon Spido Sticko Stucco Sure Mag Swift Tech Tech Pro Techia Techmax TechSpot TemplateClue Templateism Templatesilk Templatesyard Templatezy The Freelancer TheBlogger TheFocus Themeforest Themexpose TIPS AND TRICKS Topside TravelMag Trendy Trendy Travel Tumblr Under Construction Uong Jowo Veethemes Vertox VideoPlay Vigo Waverly way2themes WebBiz Wedding X-Mag Zealer ZetaMag