Posts

Showing posts from October, 2018
Array & Pointer In this session, I learned about array & pointer. Array Array is used to store the same type of data in a group. It means that all elements in the array have the same data type. To differentiate the elements in an array, they have an identifier called index. In C, index starts from 0. For example, if I want to make 3 integer variables: n1, n2, and n3; I can put those variables into an array n[index]. Here is an example of inputting elements in array : int n[5] = {1,2,3,4,5}; -> this means that I can store 5 elements in an array called n. To access the elements in an array, I just need to type the name of the array followed by the index, like n[0] = 1, n[1] = 2 and so on. I can also use pointer to access the elements(*(A+1) = 2). The example above is what we called 1D array. There are also different dimensional array like 2D and 3D. For 2D, it is the same like 1D except that 2D array have rows(array[row][col]). Example of 2D array : int n[3][4] :...
FOR Function in c Last session, i have learned how to use for loop function. For loop function can be used to repeat statements under given conditions. For example, if i want to print 12345 i don't need to use printf 5 times. Instead, i can use for loop function to print 12345. Here's the code for using the function : for( int i=1; i <= 5; i++){   printf("%d", i); } The code above will print 12345 because the condition stated to print i if i is 5 or below. For loop makes coding more efficient and you can also use it to print patterns like triangle or pyramid.