Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare string array in c

Tags:

arrays

c

string

#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".

like image 717
cethint Avatar asked Aug 02 '12 09:08

cethint


People also ask

How do you declare an array of strings?

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.

How do declare an array in C?

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};

How can you declare and initialize a string in C?

'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.


1 Answers

This way:

 char *A[] = {"Ahmet", "Mehmet", "Bülent", "Fuat"};

A is an array of pointers to char.

like image 172
ouah Avatar answered Sep 20 '22 02:09

ouah