MCA1020 Programming With C
MCA1020 Programming With C
Arthemetic operator
Unary operator
Relational operators
Logical operators
Conditional operator
Arithmetic Opertors
The basic operators for performing arithmetic are the same in many
computer languages:
+ addition
- Subtraction
*multiplication
/ division
% modulus(remainder)
Unary operator
A unary operator acts upon a single operand to produce a new value.
Relational and logical operators
An if statement like
If(x > max)
Max = x;
Is perhaps deceptivery simple. Conceptually ,we say that it checks whether
the condition x > max is true or false.
Conditional Operator
The Conditional operator (ternary operator) pair ? . is available in C to
construct conditional expressions of the form
Expr1?expr2?:expr3?
Where expr1,expr2, and expr3 are expressions.
2 . Differentiate between while and do-while statements.
Ans:- While loop :loops generally consist of two parts: one or more control expressions which
control the execution of the loop,and the body, which is the statement or set of
statements which is executed over and over.
The most basic loop in C is while loop. A while loop has one control
expression,and executes as long as that expression,and executes as long as that
expression is true. Here before executing the body of the loop,the condition is
tested. Therefore it is called an entry-controlled loop.
Do-while loop:The do.while loop is used in a situation where we need to execute the body of
the loop before the test is performed. Therefore,the body of the loop may not be
executed at all if the condition is not satisfied at the very first attempt. Where as
while loop makes a test of condition before the body of the loop is executed.
3. Describe about static and external variables.
Ans:- Static Variables
Static variables are defined within individual functions and therefore have
the same scope as automatic variables,i.e. they are local to the function in
fopen() :-
One thing to beware of when opening files is that its an operation which
may fail.The requested file might not exist, or it might be protected against
reading or writing.fopen returns a null pointer if it cant open the requested
file,and its important to check for this case before going off and using
fopens return value as a file pointer.Every call to fopen will typically be
followed with a test, like this:
Ifp = fopen(input.dat,r);
If(ifp == NULL)
{
Printf(cant open file\n);
Exit or return
}
Fclose() :Although you can open multiple files,theres a limit to how many you can
have open at once. If your program will open many files in succession,youll
want to close each one as youre done with it; otherwise the standard I/O
library could run out of the resources it uses to keep track of open files.
Closing a file simply involves calling fclose with the file pointer as its
argument:
Fclose()
Calling fclose arranges that any last ,buffered output is finally written to the
file, and those resources used by the operating system for this file are
released.