Introduction
C is a general-purpose programming language. C is commonly used in operating systems, device driver codes, and protocol stacks. The C programming language is not to be confused with the C++ programming language, which is an extension of the C programming language.
The array is nothing but a collection of elements of a similar data type. Each element stored in an array can be accessed easily using only the index of the element. In the C programming language, the character array is used to store a collection of characters at one memory location. The characters can be quoted using double quotes and single quotes. This blog will look at the difference between the single quoted and double quoted arrays.
Also Read, Sum of Digits in C, C Static Function
Difference
Double Quoted Array
In C programming language, if the characters are quoted in double quotes and the array size is not specified. In that case, the compiler automatically allots an additional blank space to the array and, in turn, increases the size of the array by one.
Let us look at an example of this case,
#include<stdio.h>
int main()
{
char arr[] = "CodingNinja";
printf("\n\nActual number of characters: 11\n");
printf("Number of elements in the Array: %lu\n\n\n", sizeof(arr));
return 1;
}

In the above example, the elements are quoted in double quotes, and the size of the array is not specified.
The above problem can be solved by providing the size of the array during the declaration of the array. For example,
#include<stdio.h>
int main()
{
char arr[11] = "CodingNinja";
printf("\n\nActual number of characters: 11\n");
printf("Number of elements in the Array: %lu\n\n\n", sizeof(arr));
return 1;
}

(Note: This solution will throw an error in the C++ programming language.)
You can also read about the dynamic arrays in c, Tribonacci Series and Short int in C Programming
Single Quoted Array
In C programming language, if the characters are quoted in single quotes and the array size is not specified. In that case, the compiler automatically doesn’t add any additional spaces to the array. For example,
#include<stdio.h>
int main()
{
char arr[] = {'N','i','n','j','a'};
printf("\n\nActual number of characters: 5\n");
printf("Number of elements in the Array: %lu\n\n\n", sizeof(arr));
return 1;
}

In the above example, each element is separately quoted in single quotes and separated by a comma(,).
Try it on an online compiler for better understanding.




