Assignment to expression with array type in c language

Assignment to expression with array type

 C programming error: In this example, we are going to see reading of array type

Error Message:

Main.c:8:13: error: assignment to expression with array type
                Alphabets=’A’;



Error Description:
#include 
#include 
 
int main()
{
   char alphabets[25];                            //Array is not indexed
   alphabets='A';
   printf("contents of Array index of 0 is : %c \n", alphabets[0]);
   return 0;
}


In above code there is an issue, alphabets is an array, cannot directly assign without index,
alphabets="A";

Error Solution:


Need to use index with array for the assignment like alphabets[0]='A';

#include 
#include 
 
int main()
{
   char alphabets[25];
   alphabets[0]='A';
   printf("contents of Array index of 0 is : %c \n", alphabets[0]);
   return 0;
}



Output:


Share this post :

Post a comment

Please share your valuable feedback and share this article in social media.

 
Support : Ranga Rajesh Kumar
Copyright © 2019. Error Solution - All Rights Reserved
Site Designed by Ranga Rajesh Kumar