hi all, i have this code which is supposed to display the elements of a char array but the problem is that its displaying funny symbols not the elements. does anyone know why?

char *list[]={"a","m","t"};
	for(i=1; i<=3; i++)
	{
		list[i]=(char *)malloc(4*sizeof(char));
	}
         printf("The elements are: ");
	for(i=1; i<=3; i++)
	{
		printf(" %s\t", &list[i]);
	}

Try an experiment and remove the loop at lines 2-5.
After that, explain what was it trying to achieve.
PS: there will still be a bug, but you'll be able to figure it out yourself.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.