0% found this document useful (0 votes)
8 views6 pages

C Notes

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views6 pages

C Notes

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

C notes

Comments Allows inclusion of any remarks that are ignored by the


compiler

syntax /* codigo */

example /*******************************************************
***
Pablo Maldonado
Practice 1.1
C fundamentals
********************************************************
**/

for Used to construct loops.

syntax for( initialization ; test; increment)


{
statements;
}
where initialization is a statement that assigns the
initial value to the indexing variable, test is a
logical statement , increment is a statment to update
the indexing variable, and statements are C code that is
executed for that particular value of the indexing
variable provided the test is true.

example for( i = 1 ; i <= 10; i = i+1 )


{
printf(" %d \t Hello! \n", i);
}

include Preprocessor directive to include a header file

syntax # include <file.h>


where file.h is a header file containing some functions
needed by your code. Standard includes are for the
standard function library, the standard input/output
routines and for the math library.

example # include <stdlib.h>


# include <stdio.h>
# include <math.h>

main Program recognized by the system that calls all


subprograms

syntax int
main(void)
{
statements;

return EXIT_SUCCESS;
}

where statements are all instructions run by your


program. Only comments, global variables, function
prototypes, functions and preprocessing directives may
precede main.

example int
main(void)
{
printf("Hello, world!\n");

return EXIT_SUCCESS;
}

printf Function to print to the standard terminal window.

syntax printf( format string, variable list);


● \n means line-feed,
● \t means tab.
● %d corresponds to an integer variable
● %f to a floating point variable or a double
precision variable.
● %lf may also be used for double precision.
● %E corresponds to printing a floating point number
or double precision variable in scientific
notation.
● %g will print a float or a double either as a
decimal fraction or in scientific notation as
appropriate.

example printf("Hello, world!\n");


printf(“The area of a circle is "%d\n”, myNumb);

scanf Function to take user input from the standard terminal


window.

syntax
scanf( format string, list of &variables);

● %d corresponds to an integer variable


● %f to a floating point variable
● %lf (long float) corresponds to a double precision
variable

example int n;
printf(" Enter the number :");
scanf("%d", &n);

Variables int, float, double, char &c

syntax char variable list and initial values;


double variable list and initial values;
float variable list and initial values;
int variable list and initial values;

example double x,y,z=1.0;


float whoseit;
char a='A',b, c='C';
b = 'B';
Operator

Symbol Operator Description Syntax

Adds two
+ Plus a+b
numeric values.

Subtracts right
– Minus operand from a–b
left operand.

Multiply two
* Multiply a*b
numeric values.

Divide two
/ Divide a/b
numeric values.

Returns the
remainder after
% Modulus diving the left a%b
operand with the
right operand.

Used to specify
+ Unary Plus the positive +a
values.

Flips the sign of


– Unary Minus -a
the value.
Increases the
++ Increment value of the a++
operand by 1.

Decreases the
-- Decrement value of the a--
operand by 1.

Symbol Operator Description Syntax

Assign the value


Simple of the right
= a=b
Assignment operand to the
left operand.

Add the right


operand and left
operand and
+= Plus and assign a += b
assign this value
a=a+b
to the left
operand.

Subtract the
right operand
Minus and and left operand a -= b
-=
assign and assign this a=a-b
value to the left
operand.
Multiply the right
operand and left
Multiply and operand and a *= b
*=
assign assign this value a= a*b
to the left
operand.

Divide the left


operand with the
Divide and right operand
/= a /= b
assign and assign this
value to the left
operand.

Assign the
remainder in the
Modulus and division of left
%= a%
assign operand with the
right operand to
the left operand.

Ref. :
● The University of Utah.
● Geeksforgeeks.

You might also like