Professional Documents
Culture Documents
Memory Management:
It supports the feature of dynamic
memory allocation. In C language,
Prof. Farzana Azeem Sheikh
Farzana.nadaf@azamcampus.org
B.C.A. (Science) Department, AISC Page 2
Unit II: C Fundamentals
{
typedef <existing_name> char ch = 'A';
<alias_name> printf("%c\n", ch);
example: return 0;
}
typedef int* IntPtr; Output:
IntPtr x, y, z; A
Type Casting:
into a higher data type. This type of are some scenarios in which we may
type conversion can be seen in the have to force type conversion.
following example. Suppose we have a variable div that
stores the division of two operands
#include<stdio.h> which are declared as an int data type.
int main(){ int result, var1=10, var2=3;
short a=10; //initializing result=var1/var2;
variable of short data type In this case, after the division
int b; //declaring int variable performed on variables var1 and var2
b=a; //implicit type casting the result stored in the variable
printf("%d\n",a); "result" will be in an integer format.
printf("%d\n",b); Whenever this happens, the value
} stored in the variable "result" loses its
meaning because it does not consider
Output the fraction part which is normally
obtained in the division of two
10 numbers.
10 To force the type conversion in such
situations, we use explicit type
#include <stdio.h> casting.
main() { It requires a type casting operator.
int number = 1; The general syntax for type casting
char character = 'k'; /*ASCII value operations is as follows:
is 107 */ type-name) expression
int sum;
sum = number + character; #include<stdio.h>
printf("Value of sum : %d\n", sum ); int main()
} {
float a = 1.2;
Output: //int b = a; //Compiler will throw an
Value of sum : 108 error for this
int b = (int)a + 1;
printf("Value of a is %f\n", a);
printf("Value of b is %d\n",b);
Explicit type casting return 0;}
In implicit type conversion, the data
type is converted automatically. There Output:
0 0 0 0 0 ^ Binary XOR (A ^ B) =
Operator copies the 49, i.e.,
bit if it is set in one 0011 0001
0 1 0 1 1 operand but not
both.
return (a > b) ?
|= Bitwise inclusive C |= 2 is a : b;
OR and same as C =
assignment C|2
operator. Increment and decrement
Operator:
Other Operators: sizeof & ternary C programming has two operators
increment ++ and decrement --
Besides the operators discussed
Increment ++ increases the value by 1
above, there are a few other
important operators whereas decrement -- decreases the
including sizeof and ? : supported by value by 1. These two operators are
the C Language. unary operators, meaning they only
operate on a single operand.
Operato Description Example
++a+,=
#include <stdio.h> A++=,+
int main() main()
{ {
int num1 = 5; int a = 1, b = 3;
int num2 = 3; b= a++ + a++ + a++ + a++ + a++;
int num3 = 2; printf("a = %d \n b = %d", a, b);
num1 = num2++;
num2 = --num3; }
printf("%d %d %d", num1, num2, a = 6, b = 15
num3); a =1 , b = 3
return 0; a = 1 , b =15
} a=2,b=4
main()
{ #include <stdio.h>
int a, b; int main()
b = 12; {
a = ++b + ++b; int i = 1;
printf("%d %d", a, b); int j = i++ + i;
printf("%d\n", j);
} }
a) 24, 12 a) 0
b) 23, 12 b) 1
c) 23, 10 c) 2
d) 24, 10 d) Compile time error
None of these
-1 -1 0 2 1