Creating your First Program
● The process of creating a C program involves writing code, compiling it, and running it on
a system.
● C is a simplistic programming language that requires you to write most of the code
yourself.
● The basic structure of a C program includes a main function that returns an integer
value.
● To display output on the screen, we use the printf() function.
● To use functions like printf(), we need to manually include a library of functions using a
directive like #include <stdio.h>.
● The C compilation process typically has three steps: Preprocessing, Compiling, and
Linking.
● The new line character () is used to indicate the end of a line in your code.
● To create a C program, we can follow these steps:
● Write the code in a text editor, such as Vim or Nano.
● Save the file with a .c extension.
● Compile the code using a C compiler like GCC.
● Run the executable file that was created after compilation.
● An example of a simple C program that prints "Hello, World!" to the console using printf()
function and \n for a new line.
Variable
● To declare a variable in C, we need to specify its type and name, such as int length;
● We can declare multiple variables of the same type in one line, separated by commas;
● Variables can be declared without assigning them a value, in which case they will be
given an initial value;
● For floating-point numbers, we need to add an f at the end of the decimal value when
assigning a value;
● Floating-point numbers are smaller and less precise than doubles, which are larger and
more precise;
● We can print out floating-point and double values using the %f format specifier in printf()
function.
, Basics of Pointers and Addresses
● Pointers in C programming refer to memory addresses of variables
● To declare a pointer variable, assign it a memory location of the same type as the
variable being pointed to
● Use the dereference operator * to retrieve the value stored at the memory location being
pointed to
● Use the ampersand symbol & to obtain the address of a variable
● Pointers are useful for memory manipulation when data is stored in consecutive blocks
of memory
● Pointers have various applications in C programming
User Inputs with Scanf
● To obtain user input in C, we use the scanf function.
● To read an integer value from user input, we use the %d format specifier in the scanf
function and specify the memory address where we want to store the input value.
● We use the ampersand (&) operator to pass the memory address of the variable where
the input value should be stored.
● The scanf function looks for values based on whitespace, so values entered on separate
lines or separated by spaces are both valid inputs.
● The scanf function matches the specified format specifier with the variable type to
ensure correct input type. For example, %f is used for floating-point numbers.
Operations and Expressions
● Providing C with two integers to divide will result in an integer result.
● To get a decimal result, the integers need to be changed to decimal values.
● The type of operands can affect the result of an operation. Dividing two integers will
result in an integer, while dividing two floating-point numbers will result in a floating-point
result.
● C will interpret the result as the right type.
● Unitary operations, including negating values, multiplication, division, and modulus, have
the highest precedence among all C operators.
● Addition and subtraction come after unitary operations in terms of precedence.
● Plus-equals is an important type of C operation.