Back to notes
What is the primary difference between source code and machine code?
Press to flip
Source code is written by humans in a programming language like C, while machine code is binary and understood by the computer.
Describe a while loop in C and provide a basic example.
A while loop repeatedly executes a block of code as long as a specified condition is true. Example: ```c int counter = 3; while (counter > 0) { printf("meow\n"); counter--; } ```
What is the difference between `float` and `double` data types in terms of precision?
`float` provides single-precision floating point arithmetic, while `double` provides double-precision, allowing for more precise representation of real numbers.
Explain the significance of the CS50 library in simplifying C programming for beginners.
The CS50 library provides simplified functions such as `get_string` and `get_int` to handle user input more easily, thereby reducing the complexity for beginner programmers.
How do you declare and call a function in C that returns the sum of two integers?
Declare the function as follows: ```c int add(int a, int b) { return a + b; } ``` Call the function using: ```c int result = add(2, 3); ```
What is the significance of including `#include <stdio.h>` in a C program?
`#include <stdio.h>` is a preprocessor directive that includes the Standard Input Output library needed for functions like `printf`.
How do you declare a function in C without a return value?
You declare a function without a return value using the `void` keyword before the function name.
How do you write an `if-else` branching logic in C to compare two integers `x` and `y`?
```c if (x < y) { printf("x is less than y\n"); } else if (x > y) { printf("x is greater than y\n"); } else { printf("x is equal to y\n"); } ```
Explain the role of a compiler in C programming.
A compiler translates source code written in C into machine code that can be executed by the computer.
Define integer overflow and explain why it is a problem in programming.
Integer overflow occurs when an arithmetic operation attempts to create a numeric value outside the range that can be represented with a given number of bits, leading to incorrect program behavior.
How do you navigate directories in the command-line interface (CLI)?
You navigate directories using commands like `cd` to change directories, `ls` to list files, `mkdir` to make a new directory, and `rmdir` to remove a directory.
What is meant by floating point imprecision in computing?
Floating point imprecision refers to the limitation of representing real numbers accurately due to finite precision of a computer's arithmetic, causing small errors or rounding issues.
What are escape sequences, and give an example of one used in C.
Escape sequences are special characters used within strings to represent newline, tab, etc. For example, `\n` represents a new line.
What is the command-line interface (CLI) command to compile a C file named `hello.c`?
The CLI command to compile `hello.c` is `make hello`.
Describe how to get user input for a string and an integer using the CS50 library.
Use `get_string` to get a string input and `get_int` to get an integer input from the user, both functions are provided by the CS50 library.
Previous
Next