Cs50 Week 1 Lecture: my summary and explanation

After submitting week 0’s Problem Set, which is meant to be a Scratch game, here comes week 1, Introduction to C language and a comparison of Scratch to C language.

Week 1 was fun, I learned about many important background files and IDE setups required in writing C, from C header #include <studio.h> to int main(void), opening curly bracket, adding semi-colon to the end of a function and so on.

As a beginner, I also learned about C Functions, Conditions, Boolean expressions, and loop, though at first glance it looks so scary.

I was able to print my first program on the screen with printf(“Hello, world\n”);, the ‘\n’ means to include a new line.

Cs50 Week 1 Summary

I learned about writing C language, starting with the Header file #include <stdio.h>, and the main function.

we used CS50 Sandbox to write and run code, The CS50 Sandbox is a virtual, cloud-based environment with the libraries and tools already installed for writing programs in various languages. At the top, there is a simple code editor, where we can type text. Below, we have a terminal window, into which we can type commands:

We are also introduced to the Data types, Conditions, loops, Function, Boolean expression.

some example of Default Data types in C are as follows

  • Int: it is used for variables that store integers.
  • Long: integers with more bits, so they can count higher.
  • Char: It is used for variables that store a single character.
  • Float: It is used for a variable that stores a floating-point value, or real number with a decimal value.
  • Double: a floating-point value with even more digits, it has 8 bytes
  • Void: it’s a type and not a data type, it is used for the program when it returns nothing. Like #int main(void)

Cs50 built-in Data types for Students

  • string: used for a variable that stores a collection or series of characters.
  • bool: it’s a data type for boolean expression of either true/false.
  • Note: To be able to use these built-in types, we need to put #include<cs50.h> at the header.

Operators

  • I learned about Arithmetic operator and Relational operator
  • Arithmetic operators are just like normal maths signs required for doing math Calculations e.g Addition(+), Subtraction(-), Multiplication(*), Modulus(%) and so on.

Relational Operator: like math, used for comparing

  • Less than (<) or less than or equal to (<=)
  • Greater than (>) or greater than or equal (>=)
  • Equality operator (==) i.e equal to
  • Inequality operator (!=) i.e not equal to
  • Note: “=” is an assignment operator in c, it’s used to add from right to left.

Conditional Statement: conditional statement allow program to make decision.

  • some examples include: if, if else, switch, ternary operator (?:)

Loop: This allow program to run over and over.

  • while loop: (it’s also called infinite loop), we can also input some line of code to run until it is false.
  • do while loop: it help program to run at least once, A do while loop is similar to while loop with one exception that it executes the statements inside the body of do-while before checking the condition.
  • for loop: to repeat program in a specific number of times.

Command Line Arguments: these are arguments or input used in contrast to Graphical User Interface.

  • ls – to list file or folder in the present directory
  • cd – to change directory
  • mkdir – to make a new directory
  • cp – to copy from file or folder in a directory
  • rm – to remove a particular directory
  • mv – to move a file or folder within one or more directory

Major Lesson

  • I Learned about including header to program in order for it to execute successfully, for example, without including #Include<stdio.h> printf(); function won’t work
  • Also learn about Data types, Loop, function, and Operators.
  • learn about doing some basic calculations like addition, subtraction, multiplication, and others with C.
  • Memory, Imprecision, and Overflow.
  • Using Clang to compile program, but make is more friendly.
  • You need to use the correct ampersand for data types….like %i for int.

Conclusion

Week 1 wasn’t that cool, since it was purely text and not that friendly like Scratch, I really made a lot of mistakes, It was my first of writing a program after writing my first Hello World, I feel so ecstatic, doing some basic calculations also unveil my eyes and motivated me.

Thanks to David. J Malan, he is the best of all time, he makes things easier for his students. If you haven’t gone through week 1, then you really need it. It’s the basics of programming with C language.

Thanks for reading….if you’ve taken Week 1 of the cs50 Harvard introductory course, do share your thoughts in the comment box below.

3 comments

  1. You are doing well, this seems to be a better site to build one’s self

    1. Thanks…really appreciate

Leave a Reply