1)What does a static variable mean?
Ans:A static variable is a special variable that is stored in the data segment unlike the default automatic variable that is stored in stack. A static variable can be initialised by using keyword static before variable name.
2)What is a pointer?
Ans:A pointer is a special variable in C language meant just to store address of any other variable or function. Pointer variables unlike ordinary variables cannot be operated with all the arithmetic operations such as '*','%' operators. It follows a special arithmetic called as pointer arithmetic.
3)What is a structure?
Ans:A structure is a collection of pre-defined data types to create a user-defined data type.
4)How to print below pattern?
1
2 3
4 5 6
7 8 9 10
Program:
#include
main() {
int i, j, ctr = 1;
for (i = 1; i < 5; i++) {
for (j = 1; j <= i; j++)
printf("%2d ", ctr++);
printf("\n");
}
}
5)How to swap two numbers using bitwise operators?
Program:
#include
main() {
int i = 65;
int k = 120;
printf("\n value of i=%d k=%d before swapping", i, k);
i = i ^ k;
k = i ^ k;
i = i ^ k;
printf("\n value of i=%d k=%d after swapping", i, k);
}
No comments:
Post a Comment