This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdio.h" | |
int main(void) { | |
float my_float_array[3]; // Once declared can only store 3 floats and will never change | |
my_float_array[0] = 1.4; // Adding each value one index at a time | |
my_float_array[1] = 2.5; | |
my_float_array[2] = 4.6; | |
int my_int_array[] = {1,2,3,4,5,6,7,8,9,10}; // Initialization holding 10 indicies or type int | |
char my_char_array[] = "Hi"; // A string is just a bunch of chars within an array | |
// the line below creates a char array in a different way. We are starting to let go of the CS50 idea of a string | |
char * my_string_array = "Goodbye"; // A char pointer points to the first element in the array like my_string_array[0] | |
printf("%.1f\n", my_float_array[1]); | |
printf("%i\n", my_int_array[9]); | |
printf("%c%c\n", my_char_array[0], my_char_array[1]); | |
printf("%c%c%c\n", my_string_array[4], my_string_array[5], my_string_array[6]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment