Hello ACC Members
My name is a anukalp gandhi. I am 2nd year student of electronics. I have read some old forum posts. Experts suggest that we should have a good knowledge of c programming before starting programming of the microcontroller. I still feel that I am not good at c programming. I have thought that I will not start programming of microcontroller until I become good at c programming.
I have some books and I'm also reading some online tutorials. After reading, I try to make my own programs. Sometimes I get successful and sometimes I fail
Question : What is array in c.
Answer : An array is used to store a set of data elements with the same data type.
For example, if we want to store six integers, we write in C:
For example, if we want to store five characters, we write in C:
For example, if we want to store five strings, we write in C:
integer size
character size
Question : What happen if we use array and what happen if we don’t use array
Answer : if I want to store two or three numbers I’ll write in c
int x = 2, y =4, z = 9
But what happen if I want to store large numbers ie 100 variables.
I can do it this in two way
I think the array is used for this reason I want to know if I have made a mistake in understanding, please let me know
My name is a anukalp gandhi. I am 2nd year student of electronics. I have read some old forum posts. Experts suggest that we should have a good knowledge of c programming before starting programming of the microcontroller. I still feel that I am not good at c programming. I have thought that I will not start programming of microcontroller until I become good at c programming.
I have some books and I'm also reading some online tutorials. After reading, I try to make my own programs. Sometimes I get successful and sometimes I fail
Question : What is array in c.
Answer : An array is used to store a set of data elements with the same data type.
For example, if we want to store six integers, we write in C:
Code:
int numbers[6] = { 0, 2, 1, 0, 1, 5 };
Code:
char letters[5] = { 'H', 'e', 'l', 'l', 'o' };
Code:
char strings[5] = { "Red", "Orange", "Yellow", "Green", "Blue" };
Code:
/* size of int depend on hardware consider it is 2 bytes so one integer take 2 bytes memory space*/
/* in the example of array there are six integer variable. Each take 2 bytes memory space */
int point[6]={ 0, 0, 1, 0, 0, 0}; /* It store six integer */
Code:
char drive[5] = { 'C', 'D', 'E', 'F', 'G' }; / it store five character, */
/* single character take one byte memory space so there total five. Each five character take one byte memory space */
Answer : if I want to store two or three numbers I’ll write in c
int x = 2, y =4, z = 9
But what happen if I want to store large numbers ie 100 variables.
I can do it this in two way
- I have to declare and initialize 100 variable but I don’t think this is good way so I have another way array
- I’ll use array to store 100 variable it’s good way because I don’t need to declare and initialize every time so I have to do only declare and initialize array to store 100 integer
Code:
Int number[100] = { 5 , 5, 8 … up to N};