Continued my studying of the C
programming language. It’s starting to get a bit more interesting. The concepts of getting user input has been introduced and pointers were mentioned. I think I probably need to review the sizing of data types again since that is starting to matter more and more with variable size declarations. Overall, it was another chill day.
TLDR;
Okay, so here are the highlights of what I did:
- Started on the “Technical Questions” section of the book “Cracking the Coding Interview” by Gayle Laakmann McDowell. I decided to get a quick intro to the
C
andJava
programming languages before I jump into building the core data structures and algorithms that will be covered in most all technical interviews. I continued with theC
for beginners video on YouTube. Got past the 1 hour mark. I stop to take notes and run example code when I think it’s important so I go slower than one might expect. Documentation is the key to long term success with learning. IMO.
Notes on C
Programming Language
Constants in C
We can declare variables as constants (unchanging) in C
by using the const
keyword in the variable declaration. For example:
const int age = 45;
char const name[] = 'Jamal';
Note: The const
keyword can be inserted before or after the variable type declaration.
Getting User Input
Whenever we want to get user input, we should prompt them. Print out what you want from them. Following the prompt we can pull the input data by using the function scanf()
int main(){
int age;
printf("Enter your age: ");
scanf("%d", &age);
double gpa;
printf("Enter your gpa: ");
scanf("%lf", &gpa);
printf("Your gpa is %f", gpa);
char grade;
printf("Enter your grade: ");
scanf("%c", &grade);
printf("Your grade is %c", grade);
// declare the name variable to be able to store 20 characters
char name[20];
printf("Enter your name: ");
scanf("%s", name);
printf("Your name is %s", name);
char name[20];
printf("Enter your name: ");
fgets(name, 20, stdin);
printf("Your name is %s", name);
return 0;
}
Note: &age
is known as a pointer. The information taken from the user is stored in the variable that we had declared earlier. Note: That when we do initialize but rather only declare a variable that is an array. We need to specify how big the array should be. Note: scanf()
by default will ignore everything after a white space. We can use the fgets()
function to get an entire line of input instead. fgets()
does have it’s problems. It will always register the enter keypress as a new line character that you have included at the end of the string (whether you want this or not).
Conclusion
That’s all for today. This is my sixth round of the “#100daysofcode” challenge. I will be continuing my work from round five into round six. I am currently working through the book “Cracking the Coding Interview” by Gayle Laakmann McDowell. My goal is to become more familiar with algorithms and data structures. This goal was derived from my goal to better understand operating systems and key programs that I use in the terminal regularly e.g. Git. This goal was in term derived from my desire to better understand the fundamental tools used for coding outside of popular GUIs. This in turn was derived from my desire to be a better back-end developer.
I have no idea if my path is correct but I am walking down this road anyways. Worst case scenario I learn a whole bunch of stuff that will help me out on my own personal projects.