Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

C - Notes - Upto Loops

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

About C:

-> C is a general-purpose programming language, developed in 1972, and still quite popular. C is
very powerful; it has been used to develop operating systems, databases, applications, etc..

-> C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories
in 1972.It is a very popular language, despite being old.C is strongly associated with UNIX, as it was
developed to write the UNIX operating system.

Compiler:

The source code written in source file is the human readable source for your program. It needs
to be "compiled", into machine language so that your CPU can actually execute the program
as per the instructions given.The compiler compiles the source codes into final executable
programs.
A compiler is a special program that translates a programming language's source code into
machine code, bytecode or another programming language.
Sample C program:
#include <stdio.h>    
int main(){    
printf("Hey There");    
return 0;   
}  

#include <stdio.h> includes the standard input output library functions. The printf()


function is defined in stdio.h . int main() The main() function is the entry point of every
program in c language.

The printf() and scanf() functions are used for input and output in C language. Both functions
are inbuilt library functions, defined in stdio.h (header file).

printf() The printf() function is used to print data on the console.

return 0 The return 0 statement, returns execution status to the OS. The 0 value is used for
successful execution and 1 for unsuccessful execution.

Constant:- A constant is a value or variable that can't be changed in the program, for example:
10, 20, 'a', 3.4, "c programming" etc.

VARIABLES:

A variable is a name of the memory location. It is used to store data. Its value can be
changed, and it can be reused many times.

It is a way to represent memory location through symbol so that it can be easily identified.

Syntax: datatype variable_name;


Examples : int a;  float b;  char c;  

Rules for defining variables

o A variable can have alphabets, digits, and underscore.


o A variable name can start with the alphabet, and underscore only. It can't start with a
digit.
o No whitespace is allowed within the variable name.
o A variable name must not be any reserved word or keyword, e.g. int, float, etc.

Local variable vs Global variable :


Variables in any programming language have a crucial role. Variables are classified into Global
variables and Local variables based on their scope. The main difference between Global and local
variables is that global variables can be accessed globally in the entire program, whereas local
variables can be accessed only within the function or block in which they are defined.

Data types :

1) Basic / Primitive -> int, float, char, long, double

2) Derived / non-primitive -> arrays, strings, pointers

3) User defined -> struct, union, enum

Keywords in C

A keyword is a reserved word. You cannot use it as a variable name, constant name, etc.
There are only 32 reserved words (keywords) in the C language.

A list of 32 keywords in the c language is given below:

auto break case char const continue default do


double else enum extern float for goto if
int long register return short signed sizeof static
struct switch typedef union unsigned void volatile while

Identifier:- We can say that an identifier is a collection of alphanumeric characters that begins
either with an alphabetical character or an underscore, which are used to represent various
programming elements such as variables, functions, arrays, structures, unions, labels, etc.

Format Specifier:- The Format specifier is a string used in the formatted input and output
functions. The format string determines the format of the input and output. The format string
always starts with a '%' character.

Memory Address:- When a variable is created in C, a memory address is assigned to the


variable.The memory address is the location of where the variable is stored on the
computer.When we assign a value to the variable, it is stored in this memory address.
-> The full form of ASCII is the American Standard Code for information interchange. It
is a character encoding scheme used for electronics communication. Each character or a
special character is represented by some ASCII code.In C programming language, a character
variable does not contain a character value itself rather the ascii value of the character
variable. The ascii value represents the character variable in numbers, and each character
variable is assigned with some number range from 0 to 127. For example, the ascii value of
'A' is 65.

-> Compile-time and Runtime are the two programming terms used in the software
development. Compile-time is the time at which the source code is converted into an
executable code while the run time is the time at which the executable code is started running.

Operators in C:

o Arithmetic Operators ( +,-,*,/,%)


o Relational Operators (<,>,<=,>=,!=,==)
o Logical Operators (&&,||,!)
o Bitwise Operators (&,|,^,~,<<,>>)
o Assignment Operator (+=,-=,*=,/=,%=,<<=,>>=,&=,^=)

Conditional Statements:

The if-else statement in C is used to perform the operations based on some specific condition.
The operations specified in if block are executed if and only if the given condition is true.

There are the following variants of if statement in C language.

o If statement
o If-else statement
o If else-if ladder
o Nested if

Looping Statements:

The looping can be defined as repeating the same process multiple times until a specific
condition satisfies. There are three types of loops used in the C language.

There are three types of loops in C language that is given below:

1. for
2. while
3. Do while

Break :- The break is a keyword in C which is used to bring the program control out of the
loop. The break statement is used inside loops or switch statement. The break statement
breaks the loop one by one, i.e., in the case of nested loops, it breaks the inner loop first and
then proceeds to outer loops. The break statement in C can be used in the following two
scenarios:
1. With switch case
2. With loop

Continue:- The continue statement in C language is used to bring the program control to the
beginning of the loop. The continue statement skips some lines of code inside the loop and
continues with the next iteration. It is mainly used for a condition so that we can skip some
code for a particular condition.

You might also like