Basics of C programming language
main()
. This is the starting point of execution after a program is loaded into memory;
//
Data types determine how much memory/space is offered to the data
Also, how the data is displayed
Declaration statements must have data type before the variable name e.g. int score
Space in memory is reserved at the time of execution
int
- 4 bytes (32 bits)short
-long
-float
real numberdouble
big real numberchar
- used to store a single character1#include <stdio.h>
2
3int main() {
4 printf("bonjour le monde!");
5 return 0;
6}
1#include <iostream>
2using namespace std;
3
4int main() {
5 printf("bonjour le monde!");
6 return 0;
7}
iostream
is a C++ library for input-output. The C equivalent would be stdio.h
gcc
and g++
to run you C and C++ code respectively&&
operator has a higher precedence than the ||
operator.!
sign is used for logical negationOverflow condition occurs when you are trying to save a value that can not be stored in the amount of memory it has been allocated. When such a condition occurs, it’ll end up in:
while
is executed zero or more times, meaning it may not even execute a single time if the condition is false.do-while
is executed one or more times, meaning it runs at least once.For example, in guessing games, you know you’re going to make at least one guess, and if the first one isn’t right then continue making guesses..
while
the condition is tested before the loop and in do-while
the condition is tested after the loopfor ( initialization condition ; continuation condition ; incrementing condition )
{
statement(s);
}
Top-down designing mechanism is based on the principle of ‘divide and conquer’ i.e. we divide a big task into smaller tasks and then accomplish them.
Functions are of two types
return
values (must return a valid data type, only one data type can be used)void
, may only display data to screen)return-value-type function-name( argument-list )
{
declarations and statements
}
return
, default is int