0% found this document useful (0 votes)
5 views

PPP Notes

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

PPP Notes

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Source Code:

- In C, source code refers to the human-readable instructions written in the C programming


language. It's the set of statements, declarations, and expressions that define the program's
logic and functionality.

- Source code files typically have a `.c` extension and are written using a text editor.

- Before a program can be executed by the computer, the source code needs to be compiled
into machine code (executable code) that the computer understands. This is done by a
compiler program.

Variables (with Data Type):

- A variable is a named storage location in memory that holds a value. It acts as a container
for data used by your program.

- Variables must be declared before they can be used. The declaration specifies the variable's
name and its data type.

- Data types define the kind of data a variable can store. Common data types in C include:

- `int`: Integer (whole numbers)

- `float`: Floating-point numbers (numbers with decimal places)

- `double`: Double-precision floating-point numbers (more precise than `float`)

- `char`: Single character

- `void`: Indicates no value

Example:

int age; // Declares an integer variable named 'age'

float pi = 3.14159; // Declares a float variable named 'pi' and initializes it with a value

Memory Allocation:

- Memory allocation refers to the process of assigning a specific amount of memory space in
the computer's memory to store a variable or other data structure.
- In C, there are two main types of memory allocation:

- Static allocation: Memory is allocated for variables declared at the global or static
scope when the program starts. This memory remains allocated for the entire program
execution.

- Dynamic allocation: Memory is allocated during program execution using functions like
`malloc`, `calloc`, and `realloc`. This allows you to allocate memory for data structures whose
size might not be known beforehand or that need to be resized during runtime. However, it's
important to remember to **free** the dynamically allocated memory using the `free` function
to avoid memory leaks.

Syntax Errors and Logical Errors:

- Syntax errors: These are errors in the code's structure that violate the grammatical rules of
the C language. Examples include missing semicolons, mismatched parentheses, or typos in
keywords.

- Logical errors: These are errors in the program's logic that cause it to produce incorrect
results even though the code compiles and runs without syntax errors. For instance, using an
incorrect formula or forgetting to include a necessary step in the logic can lead to logical
errors.

- Syntax errors are usually caught by the compiler during compilation, while logical errors can
be trickier to find and may only manifest during program execution.

Object and Executable Code:

- Object code: When you compile your C source code, the compiler translates it into machine
code (object code) that can be directly understood by the computer's processor.

- Executable code: The object code file(s) generated by the compiler may need to be linked
with library functions (pre-written code) to create a final executable file. This executable file
can then be run on your computer. The linking process is typically handled by a linker program.

- Object (in some contexts): In C, an object can also refer to a data structure or an instance of
a user-defined type (struct, union, etc.).

You might also like