Array

Array Declaration for Primitive Data Type

#include<stdio.h>
int main(){

    int a[10]; // Integer Array Declaration
    float b[10]; // Float Array Declaration
    double c[10]; // Double Array Declaration
    char d[10]; // Characte Array Declaration

    return 0;
}

Array Declaration and Initialization for Integer Data Type

#include<stdio.h>
int main(){

    int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // Initialized 10 Elements, Array Size 10
    int b[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // Initialized 10 Elements, Array Size is not explicitly defined, Array Size is 10
    int c[] = {1, 2, 3, 4, 5}; // Initialized 5 Elements, Array Size is not explicitly defined, Array Size is 5
    int d[10] = {1, 2, 3, 4, 5}; // Initialized 5 Elements, Array Size 10
    int e[10] = {1.2, 2.4, 3.6, 4.8, 5.9}; // This will store only integer value
    int f[10] = {'a', 'b', 'c', 'd', 'e'}; // This will store only integer value

    return 0;
}

String Declaration and Initialization

#include<stdio.h>
int main(){

    char a[10] = {'H', 'e', 'l', 'l', 'o', '\0'};
    char b[] = {'H', 'e', 'l', 'l', 'o', '\0'};
    char c[10] = "Hello\0";
    char d[10] = "Hello";
    char e[] = "Hello";
    char f[10] = "";
    char g[10] = {'\0'};
    char h[10];

    return 0;
}

Last updated