4 - Get Started With C (F)
4 - Get Started With C (F)
Get Started
with C
Source: W3Schools
Get Started with C < >
< >
C SYNTAX
C Syntax < >
C Syntax < >
In line 1, #include <stdio.h> is a header file library that lets us work
with input and output functions, such as printf() (used in line 4).
Header files add functionality to C programs.
In line 2, a blank line. C ignores white space. But we use it to make the
code more readable.
In line 3, main( ). This is called a function. Any code inside its curly
brackets {} will be executed.
C Syntax < >
In line 4, printf() is a function used to output/print text to the screen.
In our example it will output "Hello World!".
In line 6, the curly bracket. Do not forget to add the closing bracket } to
actually end the main function.
< >
C OUTPUT
C Output (Print Text) < >
To output values or print text in C, you can use the printf() function:
C Output (Print Text) < >
You can use as many printf() functions as you want. However, note
that it does not insert a new line at the end of the output.
Output
C Output (Print Text) < >
But using \n , we could add new lines.
C Output (Print Text) < >
What is \n exactly?
C VARIABLES
What is C Variable? < >
Variables are containers for storing data values, like numbers and
characters. These are the names you give to computer memory
locations which are used to store values in a computer program.
variable
Note: The value of a variable can be changed, hence the name variable.
What is C Variable? < >
Rules in naming variables:
C DATA TYPES
What is Data Type? < >
In C programming, data types are declarations for variables. This
determines the type and size of data associated with variables.
For example,
DECLARING
VARIABLES
Declaring (Creating) Variables < >
To create a variable, specify the type and assign it a value:
2. You can also declare a variable without assigning the value, and
assign the value later:
< >
OUTPUT
VARIABLES
Output Variables < >
Generally, to output values / print text, use printf() function.
To print different types in a single printf() function, you can use the
following:
What is Format Specifiers? < >
What is Format Specifiers? < >
Set Decimal Precision
ADD VARIABLES
TOGETHER
Add Variables Together < >
To add a variable to another variable, use the + operator:
< >
DECLARE MULTIPLE
VARIABLES
Declare Multiple Variables < >
To declare more than one variable of the same type, use a comma-
separated list:
You can also assign the same value to multiple variables of the same
type:
< >
COMMENTS IN
C
Comments in C < >
Comments can be used to explain code, and to make it more
readable. It can also be used to prevent execution when testing
alternative code.
Any text between // and the end of the line is ignored by the
compiler (will not be executed).
Comments in C < >
Multi-line Comments
- Multi-line comments start with /* and ends with */.
BASIC OPERATORS
IN C
Basic Operators in C < >
Operators
- Operators are used to perform operations on variables and
values.
USER INPUT
IN C
User Input in C < >
In C programming, scanf() is one of the commonly used function to
take input from the user. The scanf() function reads formatted input
from the standard input such as keyboards.
User Input in C < >
Example: