What is a variable?? Why do we use variables??
Variable is data holder, in which we can store some data and we can modify that data later in the program.
In C programming before we store any data in a variable we need to declare that variable.
declaring a variable:
declaring a variable means telling the compiler that what type of values you want store in that variable.
datatype variablename ; // declaring a variable
In C we have 4 types of Data Types:
1. int - for integer values
2. float - for floating points
3. double - for long floating points such as scientific values
4.char - for characters
declaring variables example:
int a; // tells the compiler that a is a integer type variable in which you want to store integer value.
float f; //
double d;
char c;
once you declare the variables you can store actual values in those variables.
As I told you variable is data holder. so once you declare any variable C compiler will allocate memory depending on the specified data type.
int a; when do you this one C compiler will allocate 4 bytes of space for this variable called a.
its like this a
Friday, November 19, 2010
Monday, November 8, 2010
C QUESTION AND ANSWERS: 3
| 1. | Point out the correct statements are correct about the program below? | ||||||||||||||||
Answer: Option D Explanation: There are 2 errors in this program. 1. "Undefined symbol x" error. Here x is not defined in the program. 2. Here while() statement syntax error. Learn more problems on : Control Instructions Discuss about this problem : Discuss in Forum |
| 2. | What will be the output of the program? | ||||||||||||||||
Answer: Option C Explanation: Step 1: int i=-3, j=2, k=0, m; here variable i, j, k, m are declared as an integer type and variable i, j, k are initialized to -3, 2, 0 respectively. Step 2: m = ++i && ++j || ++k; becomes m = (-2 && 3) || ++k; becomes m = TRUE || ++k;. (++k) is not executed because (-2 && 3) alone return TRUE. Hence this statement becomes TRUE. So it returns '1'(one). Hence m=1. Step 3: printf("%d, %d, %d, %d\n", i, j, k, m); In the previous step the value of i,j are increemented by '1'(one). Hence the output is "-2, 3, 0, 1". Learn more problems on : Expressions Discuss about this problem : Discuss in Forum |
| 3. | What will be the output of the program? | ||||||||||||||||
|
| 4. | What will be the output of the program? | ||||||||||||||||
Answer: Option B Explanation: The macro FUN(arg) prints the statement "IndiaBIX..." untill the while condition is satisfied. Step 1: int i=2; The variable i is declared as an integer type and initialized to 2. Step 2: FUN(i<3); becomes, After the 2 while loops the value of i becomes '0'(zero). Hence the while loop breaks. Hence the output of the program is "IndiaBIX... IndiaBIX..." Learn more problems on : C Preprocessor Discuss about this problem : Discuss in Forum |
| 5. | What will be the output of the program? | ||||||||||||||||
Answer: Option B Explanation: The macro MAX(a, b) (a > b ? a : b) returns the biggest value of the given two numbers. Step 1 : int x; The variable x is declared as an integer type. Step 2 : x = MAX(3+2, 2+7); becomes, => x = (3+2 > 2+7 ? 3+2 : 2+7) => x = (5 > 9 ? 5 : 9) => x = 9 Step 3 : printf("%d\n", x); It prints the value of variable x. Hence the output of the program is 9. Learn more problems on : C Preprocessor Discuss about this problem : Discuss in Forum |
| 6. | What will be the output of the program? | ||||||||||||||||
Answer: Option C Explanation: The macro MAX(a, b, c) (a>b ? a>c ? a : c: b>c ? b : c) returns the biggest of given three numbers. Step 1: int x; The variable x is declared as an integer type. Step 2: x = MAX(3+2, 2+7, 3+7); becomes, => x = (3+2 >2+7 ? 3+2 > 3+7 ? 3+2 : 3+7: 2+7 > 3+7 ? 2+7 : 3+7) => x = (5 >9 ? (5 > 10 ? 5 : 10): (9 > 10 ? 9 : 10) ) => x = (5 >9 ? (10): (10) ) => x = 10 Step 3: printf("%d\n", x); It prints the value of 'x'. Hence the output of the program is "10". Learn more problems on : C Preprocessor Discuss about this problem : Discuss in Forum |
| 7. | What will be the output of the program ? | ||||||||||||||||
|
| 8. | In the following program add a statement in the function fact(). such that the factorial gets stored in j. | ||||||||||||||||
|
| 9. | Is the NULL pointer same as an uninitialised pointer? | ||||||||
|
| 10. | What will be the output of the program if the array begins at address 65486? | ||||||||||||||||
Answer: Option B Explanation: Step 1: int arr[] = {12, 14, 15, 23, 45}; The variable arr is declared as an integer array and initialized. Step 2: printf("%u, %u\n", arr, &arr); Here, The base address of the array is 65486. => arr, &arr is pointing to the base address of the array arr. Hence the output of the program is 65486, 65486 Learn more problems on : Arrays Discuss about this problem : Discuss in Forum |
| 11. | What will be the output of the program ? | ||||||||||||||||
Answer: Option C Explanation: Step 1: char str1[20] = "Hello", str2[20] = " World"; The variable str1 andstr2 is declared as an array of characters and initialized with value "Hello" and " World" respectively. Step 2: printf("%s\n", strcpy(str2, strcat(str1, str2))); => strcat(str1, str2)) it append the string str2 to str1. The result will be stored instr1. Therefore str1 contains "Hello World". => strcpy(str2, "Hello World") it copies the "Hello World" to the variable str2. Hence it prints "Hello World". Learn more problems on : Strings Discuss about this problem : Discuss in Forum |
| 12. | For the following statements will arr[3] and ptr[3] fetch the same character? char arr[] = "IndiaBIX"; char *ptr = "IndiaBIX"; | ||||||||
Answer: Option A Explanation: Yes, both the statements prints the same character 'i'. Learn more problems on : Strings Discuss about this problem : Discuss in Forum |
| 13. | It is not possible to create an array of pointer to structures. | ||||||||
Answer: Option B Learn more problems on : Structures, Unions, Enums Discuss about this problem : Discuss in Forum |
| 14. | Can I increase the size of statically allocated array? | ||||||||
Answer: Option B Learn more problems on : Memory Allocation Discuss about this problem : Discuss in Forum |
| 15. | What will be the output of the program? | ||||||||||||||||
Answer: Option D Learn more problems on : Variable Number of Arguments Discuss about this problem : Discuss in Forum |
| 16. | Point out the error in the following program. | ||||||||||||||||
Answer: Option B Explanation: The call to show() is improper. This is not the way to pass variable argument list to a function.Learn more problems on : Variable Number of Arguments Discuss about this problem : Discuss in Forum |
| 17. | In a function that receives variable number of arguments the fixed arguments passed to the function can be at the end of argument list. | ||||||||
Answer: Option B Learn more problems on : Variable Number of Arguments Discuss about this problem : Discuss in Forum |
| 18. | What will be the output of the program? | ||||||||||||||||
Answer: Option A Learn more problems on : Complicated Declarations Discuss about this problem : Discuss in Forum |
| 19. | What will be the output of the program? | ||||||||||||||||
Answer: Option B Learn more problems on : Complicated Declarations Discuss about this problem : Discuss in Forum |
| 20. | ftell() returns the current position of the pointer in a file stream. | ||||||||
Answer: Option A Explanation: The ftell() function shall obtain the current value of the file-position indicator for the stream pointed to by stream. Example: Learn more problems on : Library Functions Discuss about this problem : Discuss in Forum |
Subscribe to:
Posts (Atom)

