This document provides an introduction to the C programming language. It explains that C allows programmers to write code using functions and keywords rather than billions of 1s and 0s. It then discusses some basic C concepts like #include, main(), printf(), variables, data types, if/else statements, for loops, and functions. The document is meant to explain the basic building blocks of a C program to a beginner reader.
2. Before the programming language:
A circuit which adds two numbers
But one problem arises here. To be able to write a computer program by
typing out billions of 1s and 0s would require superhuman brainpower,
and even then it would probably take you a lifetime or two to write.
3. Using programming language:
You can say that any programming language is just like a
dictionary which contains words that mean certain circuits.
For example : addition, multiplication, etc.
6. Make the things simpler !
#include <stdio.h> includes the standard input output library
functions. The printf() function is defined in stdio.h . (you can think of
a library as a dictionary contains words and their meanings)
void main() The main() function is the entry point of every
program in c language. The void keyword specifies that it returns no
value. (Itll be explained soon)
printf() The printf() function is used to print data on the console.
7. What is #include <stdio.h>
stdio stands for standard
input/output which contains
functions that help in the process of
input or output.
Its more or less like including a
dictionary which contains words and
their meanings (function and their
definition)
Without it you cannot write printf()
because it will be meaningless to the
compiler.
10. printf
The syntax :
printf(format string,arguments_list);
Place holders can be %d(integer), %c(character), %s(string), %f(float)
Example :
int x=50;
printf(My number is integer and its value is %d,x);
18. If and if-else statement :
used to execute the code if condition is true or false.
19. The from of if-else statement:
if(condition1){
//code to be executed if condition1 is true
} else { // code to be executed if all the conditions are false
}
20. Examples: Try it yourself ..
The number is greater than 50 ! Here is the rest of
my program
Here is the rest of my program
Can you make the user enter the number
instead of writing it in the program ?
21. Operators to do complicated jobs :
If (x>5&&x<10) // if x is greater than
5 and less than 10
If (x==6||x==5) // if x is equal 6 or 5
If(x!=6) // if x is not equal to 6
28. Example: Try it yourself ..
The output :
The current value of x is 0
The current value of x is 1
The current value of x is 2
The current value of x is 3
The current value of x is 4
The current value of x is 5
The current value of x is 6
The current value of x is 7
The current value of x is 8
The current value of x is 9
37. Void in functions:
Its the function that doesnt return
anything !
Its the function that doesnt
take or return anything !
38. Whats next ?
CS50: Introduction to Computer Science Embedded Systems - Shape The World YouTube Tutorials
39. Arduino Program:
int main(void)
{
setup();
while (1) // infinite loop
loop();
return 0;
}
void setup(){
}
void loop (){
}
The main function which contains
calling 2 functions : setup and loop
The setup function which
will be called only one time
The setup function which
will be called only one time