#include<stdio.h>
int main()
{
int i;
string A[]={"Ahmet", "Mehmet", "Bulent", "Fuat"};
for(i=0;i<=3;i++){
printf("%s",A[i]);
}
return 0;
}
How can i see my array's elements as output?
Compiler says "'string' undeclared".
You can also initialize the String Array as follows:String[] strArray = new String[3]; strArray[0] = “one”; strArray[1] = “two”; strArray[2] = “three”; Here the String Array is declared first. Then in the next line, the individual elements are assigned values.
To create an array, define the data type (like int ) and specify the name of the array followed by square brackets []. To insert values to it, use a comma-separated list, inside curly braces: int myNumbers[] = {25, 50, 75, 100};
'C' also allows us to initialize a string variable without defining the size of the character array. It can be done in the following way, char first_name[ ] = "NATHAN"; The name of Strings in C acts as a pointer because it is basically an array.
This way:
char *A[] = {"Ahmet", "Mehmet", "Bülent", "Fuat"};
A
is an array of pointers to char
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With