CodersEditor Tutorials

CodersEditor Tutorials

  • Online IDE
  • Q&A
  • C Programming
  • Java
  • GraphQL.NET
  • System Software

›Arrays

C Programming

    Introduction

    • Overview
    • Installation & Setup
    • C Program Structure
    • Keywords & Identifiers
    • Data Types
    • Variables & Constants
    • Scope Rules
    • Storage Class
    • Standard Input and Output
    • Operators

    Control Flow/Decision Making

    • Overview
    • if Statement
    • if else Statement
    • Nested If statement
    • Switch Statement
    • Nested Switch Statement
    • Conditional Operators

    Loop

    • Loops Overview
    • While loop
    • For Loop
    • Do while
    • Nested Loops
    • Break
    • Continue Statement
    • Goto statement

    Arrays

    • Arrays
    • Multi Dimensional Arrays
    • Arrays & Functions

    Pointers

    • Pointers Basics
    • Pointers and Arrays
    • Pointers and Functions
    • Memory allocation

    Strings

    • String Basics
    • String Functions

    C Programming Examples

    • Basic Example 1

Arrays in C

An array in C is a collection of items stored at common border memory locations and elements can be accessed randomly using indices of an array.

They store only similar type of elements. They are used to store the common data types like, int, float etc. An array in C can store derived data types such as the structures, pointers etc.

Declaring Array in C

To declare an array in C, you need to specify the type of the elements and the number of elements required by the array.

Syntax for Declaring an Array

type arrayName [ arraySize ];

Initializing an Array

For initializing an array, you need to store the elements in the array.

Syntax for Initialising an Array

type arrayName [ arraySize ] = {data/elements};

Accessing Array Elements

An element is accessed by indexing the array name. The required value is called by its index in [ ].

Syntax for Accessing an Array

new_array= arrayName [index];

Sample program for Array

#include<stdio.h>  
int main()
{      
    int i=0;    
    int marks[5]; 
    marks[0]=90;   
    marks[1]=70;    
    marks[2]=80;    
    marks[3]=75;    
    marks[4]=65;    
    for(i=0;i<5;i++){      
    printf("%d \n",marks[i]);    
    }
    return 0;  
}

Output

90
70
80
75
65
← Goto statementMulti Dimensional Arrays →
  • Declaring Array in C
    • Syntax for Declaring an Array
  • Initializing an Array
    • Syntax for Initialising an Array
  • Accessing Array Elements
    • Syntax for Accessing an Array
  • Sample program for Array
  • Output
CodersEditor Tutorials
CoderdEditor Developer Tools
CodersEditor Online EditorGit Flavoured Markup EditorFree Online JSON FormatterFind My IP Address Details
Tutorials
C ProgrammingJava
Copyright © 2021 CodersEditor.com