You are on page 1of 147

C

@: Ho me >C Pro gra mm ing >D ecl ara tion s and Init iali zati ons > Gen eral Que stio ns

Is the following statement a declaration or definition?

extern int i;
A. C. Declaration B. D. Definition Error

Function

Answer & Explanation

Answer: Option A Explanation: Declaring is the way a programmer tells the compiler to expect a particular type, be it a variable, class/struct/union type, a function type (prototype) or a particular object instance. (ie. extern int i) Declaration never reserves any space for the variable or instance in the program's memory; it simply a "hint" to the compiler that a use of the variable or instance is expected in the program. This hinting is technically called "forward reference". View Answer Workspace Report Discuss in Forum 2. Identify which of the following are declarations 1 : extern int x; 2 : float square ( float x ) { ... }

3 : double pow(double, double);

A. C.

1 1 and 3

B. D.

2 3

Answer & Explanation

Answer: Option C Explanation: extern int x; - is an external variable declaration. double pow(double, double); - is a function prototype declaration. Therefore, 1 and 3 are declarations. 2 is definition. View Answer Workspace Report Discuss in Forum

3.

In the following program where is the variable a getting defined and where it is getting declared?

#include<stdio.h>
int main() { extern int a; printf("%d\n", a); return 0; } int a=20; A. B. C. D.

extern int a is declaration, int a = 20 is the definition int a = 20 is declaration, extern int a is the definition int a = 20 is definition, a is not defined a is declared, a is not defined

Answer & Explanation

Answer: Option A Explanation: - During declaration we tell the datatype of the Variable. - During definition the value is initialized.

View Answer Workspace Report Discuss in Forum

4.

When we mention the prototype of a function are we defining the function or declaring it? A. C. Defining Prototyping B. D. Declaring

Calling

Answer & Explanation

Answer: Option B Explanation: A function prototype in C or C++ is a declaration of a function that omits the function body but does specify the function's name, argument types and return type. While a function definition specifies what a function does, a function prototype can be thought of as specifying its interface. View Answer Workspace Report Discuss in Forum

5.

What's the difference between following declarations? 1 : extern int fun(); 2 : int fun();

A. B. C. D.

extern int fun(); is in another file


No difference, except extern int fun(); is in another file

int fun(); is overrided with extern int fun();


None of these

Answer & Explanation

Answer: Option B Explanation:

extern int fun(); declaration in C is to indicate the existence of a global function and it
is defined externally to the current module or in another file.

int fun(); declaration in C is to indicate the existence of a function inside the current
module or in the same file

6.

What are the types of linkages? A. C. Internal and External External and None B. D. External, Internal and None

Internal

Answer & Explanation

Answer: Option B Explanation: External Linkage-> means global, non-static variables and functions. Internal Linkage-> means static variables and functions with file scope. None Linkage-> means Local variables. View Answer Workspace Report Discuss in Forum 7. Which of the following special symbol allowed in a variable? A. C. * (asterisk) - (hyphen) B. D. | (pipeline) _ (underscore)

Answer & Explanation

Answer: Option D Explanation: Variable names in C are made up of letters (upper and lower case) and digits. The underscore character ("_") is also permitted. Names must not begin with a digit. Examples of valid (but not very descriptive) C variable names: => foo => Bar => BAZ => foo_bar => _foo42 => _ => QuUx View Answer Workspace Report Discuss in Forum 8. By default a real number is treated as a A. C. float long double B. D. double

far double

Answer & Explanation

Answer: Option B

Explanation: In computing, 'real number' often refers to non-complex floating-point numbers. It include both rational numbers, such as 42 and 3/4, and irrational numbers such as pi = 3.14159265... When the accuracy of the floating point number is insufficient, we can use thedouble to define the number. The double is same as float but with longer precision and takes double space (8 bytes) than float. To extend the precision further we can use long double which occupies 10 bytes of memory space. View Answer Workspace Report Discuss in Forum 9. Which of the following is not user defined data type? 1:

struct book { char name[10]; float price; int pages; };

2: 3:

long int l = 2.35;

enum day {Sun, Mon, Tue, Wed}; 1 3 B. D. 2

A. C.

Both 1 and 2

Answer & Explanation

Answer: Option B Explanation: C data types classification are 1. Primary data types 1. int 2. char 3. float 4. double 5. void Secondary data types (or) User-defined data type 1. Array 2. Pointer 3. Structure 4. Union 5. Enum

2.

So, clearly long int l = 2.35; is not User-defined data type.

(i.e.long int l = 2.35; is the answer.) View Answer Workspace Report Discuss in Forum 10. Which of the following statements should be used to obtain a remainder after dividing 3.14 by 2.1 ? A. B. C. D. rem = 3.14 % 2.1; rem = modf(3.14, 2.1); rem = fmod(3.14, 2.1); Remainder cannot be obtain in floating point division.

Answer & Explanation

Answer: Option C Explanation:

fmod(x,y) - Calculates x modulo y, the remainder of x/y. This function is the same as the modulus operator. But fmod() performs floating point
divisions. Example:

#include <stdio.h> #include <math.h> int main () { printf ("fmod of 3.14/2.1 is %lf\n", fmod (3.14,2.1) ); return 0; }
Output: fmod of 3.14/2.1 is 1.040000

11. How would you round off a value from 1.66 to 2.0? A. C. ceil(1.66) B. D. floor(1.66) roundto(1.66)

roundup(1.66)

Answer & Explanation

Answer: Option A

Explanation:

/* Example for ceil() and floor() functions: */ #include<stdio.h> #include<math.h> int main() { printf("\n Result : %f" , ceil(1.66) ); printf("\n Result : %f" , floor(1.66) ); return 0; } // Output: Result : 2.000000 // Output: Result : 1.000000

C Programming :: Declarations and Initializations


@ : Home > C Programming > Declarations and Initializations > Find Output of Program

1.

What will be the output of the program?

#include<stdio.h>
int X=40; int main() { int X=20; printf("%d\n", X); return 0; } A. C. 20 B. D. 40 No Output

Error

Answer & Explanation

Answer: Option A Explanation: Whenever there is conflict between a local variable and global variable, the local variable gets priority. View Answer Workspace Report Discuss in Forum 2. What will be the output of the program?

#include<stdio.h>

int main() { int X=40; { int X=20; printf("%d ", X); } printf("%d\n", X); return 0; } A. C. 40 40 20 B. D. 20 40

Error

Answer & Explanation

Answer: Option B Explanation: In case of a conflict between a local variable and global variable, the local variable gets priority. View Answer Workspace Report Discuss in Forum 3. In the following program how long will the for loop get executed?

#include<stdio.h>
int main() { int i; for(;scanf("%s", &i); printf("%d\n", i)); return 0; } A. B. C. D. The for loop would not get executed at all The for loop would get executed only once The for loop would get executed 5 times The for loop would get executed infinite times

Answer & Explanation

Answer: Option D Explanation: During the for loop execution scanf() ask input and then printf() prints that given input. This process will be continued repeatedly because, scanf() returns the number of input given, the condition is always true(user gives a input means it reurns '1').

Hence this for loop would get executed infinite times. View Answer Workspace Report Discuss in Forum 4. What will be the output of the program?

#include<stdio.h>
int main() { extern int i; i = 20; printf("%d\n", sizeof(i)); return 0; } A. C. 2 vary from compiler B. D. 4 Linker Error : Undefined symbol 'i'

Answer & Explanation

Answer: Option D Explanation: Linker Error : Undefined symbol 'i' extern int i specifies to the compiler that the memory for 'i' is allocated in some other program and that address will be given to the current program at the time of linking. But linker finds that no other variable of name 'i' is available in any other program with memory space allocated for it. Hence a linker error has occurred . View Answer Workspace Report Discuss in Forum 5. What is the output of the program?

#include<stdio.h>
int main() { extern int a; printf("%d\n", a); return 0; } int a=20; A. C. 20 B. D. 0 Error

Garbage Value

Answer & Explanation

Answer: Option A Explanation:

extern int a; indicates that the variable a is defined elsewhere, usually in a separate

source code module.

printf("%d\n", a); it prints the value of local variable int a = 20. Because, whenever
there is a conflict between local variable and global variable, local variable gets the highest priority. So it prints 20.

6.

What is the output of the program

#include<stdio.h>
int main() { extern int fun(float); int a; a = fun(3.14); printf("%d\n", a); return 0; } int fun(aa) float aa; { return ((int)aa); } A. C. 3 0 B. D. 3.14 Error

Answer & Explanation

Answer: Option D Explanation: 2 Errors 1. Type mismatch in redeclaration of fun 2. Type mismatch in parameter aa View Answer Workspace Report Discuss in Forum 7. What is the output of the program

#include<stdio.h>
int main() { char *s1; char far *s2; char huge *s3; printf("%d, %d, %d\n", sizeof(s1), sizeof(s2), sizeof(s3)); return 0; } A. C. 2, 4, 6 2, 4, B. D. 4, 4, 2 2, 2, 2

4
Answer & Explanation

Answer: Option C Explanation: Any pointer size is 2 bytes. (only 16-bit offset) So, char *s1 = 2 bytes. So, char far *s2; = 4 bytes. So, char huge *s3; = 4 bytes. A far, huge pointer has two parts: a 16-bit segment value and a 16-bit offset value. View Answer Workspace Report Discuss in Forum 8. What is the output of the program

#include<stdio.h>
int main() { struct emp { char name[20]; int age; float sal; }; struct emp e = {"Tiger"}; printf("%d, %f\n", e.age, e.sal); return 0; } A. C. 0, 0.000000 Error B. D. Garbage values None of above

Answer & Explanation

Answer: Option A Explanation: When an automatic structure is partially initialized remaining elements are initialized to 0(zero). View Answer Workspace Report Discuss in Forum 9. What is the output of the program

#include<stdio.h>
int main() { int a[5] = {2, 3}; printf("%d, %d, %d\n", a[2], a[3], a[4]); return 0; }

A. C.

Garbage Values 3, 2, 2

B. D.

2, 3, 3 0, 0, 0

Answer & Explanation

Answer: Option D Explanation: When an automatic array is partially initialized, the remaining elements are initialized to 0. View Answer Workspace Report Discuss in Forum 10. What is the output of the program

#include<stdio.h>
int main() { int x = 10, y = 20, z = 5, i; i = x < y < z; printf("%d\n", i); return 0; } A. C. 0 Error B. D. 1

None of these

Answer & Explanation

Answer: Option B Explanation: Since x < y turns to be TRUE it is replaced by 1. Then 1 < z is compared and to beTRUE. The 1 is assigned to i.

11. What is the output of the program

#include<stdio.h>
int main() { enum status { pass, fail, atkt}; enum status stud1, stud2, stud3; stud1 = pass; stud2 = atkt; stud3 = fail; printf("%d, %d, %d\n", stud1, stud2, stud3); return 0; } A. C. 0, 1, 2 0, 2, 1 B. D. 1, 2, 3 1, 3, 2

Answer & Explanation

Answer: Option C Explanation:

enum takes the format like {0,1,2..) so pass=0, fail=1, atkt=2 stud1 = pass (value is 0) stud2 = atkt (value is 2) stud3 = fail (value is 1)
Hence it prints 0, 2, 1 View Answer Workspace Report Discuss in Forum 12. What is the output of the program

#include<stdio.h>
int main() { union a { int i; char ch[2]; }; union a u; u.ch[0] = 3; u.ch[1] = 2; printf("%d, %d, %d\n", u.ch[0], u.ch[1], u.i); return 0; } A. C. 3, 2, 515 3, 2, 5 B. D. 515, 2, 3 None of these

Answer & Explanation

Answer: Option A Explanation:

printf("%d, %d, %d\n", u.ch[0], u.ch[1], u.i); It prints the value ofu.ch[0] = 3, u.ch[1] = 2 and it prints the value of u.i means the value of entire union size.

So the output is 3, 2, 515.

C Programming :: Declarations and Initializations


@ : Home > C Programming > Declarations and Initializations > Point Out Errors

1.

Point out the error in the following program.

#include<stdio.h>
int main() { display(); return 0; } void display() { printf("IndiaBIX.com"); } A. B. C. D. No error

display() doesn't get invoked display() is called before it is defined


None of these

Answer & Explanation

Answer: Option C Explanation: In this program the compiler will not know that the function display() exists. So, the

compiler will generate "Type mismatch in redeclaration of function display()". To over come this error, we have to add function prototype of function display(). Another way to overcome this error is to define the function display() before theint main(); function.

#include<stdio.h> void display(); /* function prototype */ int main() { display(); return 0; } void display() { printf("IndiaBIX.com"); }
Output: IndiaBIX.com View Answer Workspace Report Discuss in Forum 2. Point out the error in the following program.

#include<stdio.h>
int main() { char *cptr, c; void *vptr, v; c = 10; v = 0; cptr = &v; vptr = &v; return 0; } A. B. C. D. Error: Cannot assign v to void pointer type Error: Size of v is unknown or zero No error. None of these.

Answer & Explanation

Answer: Option B Explanation: This is because v is declared as void pointer but not a simple variable of type void.

View Answer Workspace Report Discuss in Forum 3. Point out the error in the following program.

#include<stdio.h>
struct emp { char name[20]; int age; }; int main() { emp int xx; int a; printf("%d\n", &a); return 0; } A. C. Error: in printf No error. B. D. Error: in emp int xx; None of these.

Answer & Explanation

Answer: Option B Explanation: There is an error in the line emp int xx; To overcome this error, remove the int and add the struct at the begining of emp int xx;

#include<stdio.h> struct emp { char name[20]; int age; }; int main() { struct emp xx; int a; printf("%d\n", &a); return 0; }
View Answer Workspace Report Discuss in Forum 4. Point out the error in the following program.

#include<stdio.h>
int main() { int (*p)() = fun; (*p)(); return 0; }

int fun() { printf("IndiaBix.com\n"); return 0; } A. B. C. D. Error: in int(*p)() = fun; Error: fun() prototype not defined No error None of these

Answer & Explanation

Answer: Option B Explanation: The compiler will not know that the function int fun() exists. So we have to define the function prototype of int fun(); To overcome this error, see the below program

#include<stdio.h> int fun(); /* function prototype */ int main() { int (*p)() = fun; (*p)(); return 0; } int fun() { printf("IndiaBix.com\n"); return 0; }
View Answer Workspace Report Discuss in Forum 5. Which of the following is correct about err used in the declaration given below?

typedef enum error { warning, test, exception } err; A. B. C. D. It is a typedef for enum error. It is a variable of type enum error. The statement is erroneous. It is a structure.

Answer & Explanation

Answer: Option A Explanation: A typedef gives a new name to an existing data type. So err is a new name for enum error.

C Programming :: Declarations and Initializations


@ : Home > C Programming > Declarations and Initializations > Point Out Correct Statements

1.

Point Out Correct Statement

1 : typedef long a; extern int a c; 2 : typedef long a; extern a int c; 3 : typedef long a; extern a c; A. C. 1 correct 3 correct B. D. 2 correct 1, 2, 3 are correct

Answer & Explanation

Answer: Option C Explanation:

typedef long a; extern int a c; while compiling this statement becomes extern int long c;. This will
result in to "Declaration syntax error".

typedef long a; extern a int c; while compiling this statement becomes extern long int c;. This will
result in to "Too many types in declaration error".

typedef long a; extern a c; while compiling this statement becomes extern long c;. This is a valid c declaration statement. It says variable c is long data type and defined in some other file or
module. So, Option C is the correct answer. View Answer Workspace Report Discuss in Forum 2. Which of the structure is incorrcet? 1:

struct aa { int a; float b; };

2:

struct aa { int a; float b; struct aa var; };

3:

struct aa

{ int a; float b; struct aa *var; }; A. C. 1 3 B. D. 2

1, 2, 3

Answer & Explanation

Answer: Option B Explanation: Option B gives "Undefined structure in 'aa'" error. View Answer Workspace Report Discuss in Forum 3. Which of the definition is correct? A. C. int length; B. D. char int; float double;

int long;

View Answer Workspace Report Discuss in Forum 4. Which of the structure is corrcet? 1:

struct book { char name[10]; float price; int pages; };

2:

struct aa { char name[10]; float price; int pages; }

3:

struct aa { char name[10]; float price; int pages; } 1 B. 2

A.

C.

D.

All of above

Answer & Explanation

Answer: Option A Explanation: In 2 and 3 semicolon are missing in structure element. View Answer Workspace Report Discuss in Forum 5. Which of the following operations are INCORRECT? A.

int i = 35; i = i%5;

B.

short int j = 255; j = j;

C.

long int k = 365L; k = k;

D.

float a = 3.14; a = a%3;

Answer & Explanation

Answer: Option D Explanation:

float a = 3.14; a = a%3; gives "Illegal use of floating point" error.


The modulus (%) operator can only be used on integer types. We have to usefmod() function in math.h for float values.

6.

Which of the following correctly represents a long double constant? A. C. 6.68 6.68f B. D. 6.68 L 6.68LF

Answer & Explanation

Answer: Option B Explanation:

6.68 is double. 6.68L is long double constant. 6.68f is float constant. 6.68LF is not allowed in c.

C Programming :: Declarations and Initializations

@ : Home > C Programming > Declarations and Initializations > True / False Questions

1.

If the definition of the external variable occurs in the source file before its use in a particular function, then there is no need for an extern declaration in the function. A. True B. False

Answer & Explanation

Answer: Option A Explanation: True, When a function is declared inside the source file, that function(local function) get a priority than the extern function. So there is no need to declare a function asextern inside the same source file. View Answer Workspace Report Discuss in Forum 2. Size of short integer and long integer would vary from one platform to another. A. True B. False

Answer & Explanation

Answer: Option A Explanation: True, Depending on the operating system/compiler/system architecture you are working on, the range of data types can vary. View Answer Workspace Report Discuss in Forum 3. Size of short integer and long integer can be verified using the sizeof()operator. A. True B. False

Answer & Explanation

Answer: Option A Explanation: True, we can find the size of short integer and long integer using thesizeof() operator. Example:

#include<stdio.h> int main() { short int i = 10; long int j = 10; printf("short int is %d bytes.,\nlong int is %d bytes.", sizeof(i),sizeof(j)); return 0;

}
Output: short int is 2 bytes. long int is 4 bytes. View Answer Workspace Report Discuss in Forum 4. A float is 4 bytes wide, whereas a double is 8 bytes wide. A. True B. False

Answer & Explanation

Answer: Option A Explanation: True,

float = 4 bytes. double = 8 bytes.


View Answer Workspace Report Discuss in Forum 5. Range of float id -2.25e-308 to 2.25e+308 A. True B. Fals e

Answer & Explanation

Answer: Option B Explanation: False, The range of float is -3.4e-38 to 3.4e+38.

6.

Range of double is -1.7e-38 to 1.7e+38 A. True B. Fals e

Answer & Explanation

Answer: Option B Explanation: False, The range of double is -1.7e-308 to 1.7e+308. View Answer Workspace Report Discuss in Forum 7. A long double should be used if range of a double is not enough to accommodate a real number. A. True B. False

Answer & Explanation

Answer: Option A Explanation: True, we can use long double; if double range is not enough.

double = 8 bytes. long double = 10 bytes.

C Programming :: Declarations and Initializations


@ : Home > C Programming > Declarations and Initializations > Yes / No Questions

1.

Is it true that a global variable may have several declarations, but only one definition? A. Yes B. No

Answer & Explanation

Answer: Option A Explanation: Yes, In all the global variable declarations, you need to use the keyword extern. View Answer Workspace Report Discuss in Forum 2. Is it true that a function may have several declarations, but only one definition? A. Yes B. No

Answer & Explanation

Answer: Option A Explanation: Yes, but the function declarations must be identical. View Answer Workspace Report Discuss in Forum 3. Suppose a program is divided into three files f1, f2 and f3, and a variable is defined in the file f1 but used in files f2 and f3. In such a case would we need theextern declaration for the variables in the files f2 and f3? A. Yes B. No

Answer & Explanation

Answer: Option A Explanation: Yes, Consider,

variable f1 in FILE1.C variable f2 in FILE2.C variable f3 in FILE3.C If we need to use the variable f1 in the files FILE2.C and FILE3.C We have to declare the variable f1 as extern int f1; in the files FILE2.C and FILE3.C. View Answer Workspace Report Discuss in Forum 4. Global variable are available to all functions. Does there exist a mechanism by way of which it available to some and not to others. A. Yes B. No

Answer & Explanation

Answer: Option B Explanation: The only way this can be achieved is to define the variable locally in main() instead of defining it globally and then passing it to the functions which need it. View Answer Workspace Report Discuss in Forum 5. Is there any difference int the following declarations?

int myfun(int arr[]); int myfun(arr[20]);


A. Yes B. No

Answer & Explanation

Answer: Option A Explanation: Yes, we have to specify the data type of the parameter when passing to a function.

C Programming :: Control Instructions


@ : Home > C Programming > Control Instructions > General Questions

1.

Which of the following is not logical operator? A. C. & B. D. && !

||

Answer & Explanation

Answer: Option A Explanation: Bitwise operators: & is a Bitwise AND operator. Logical operators: && is a Logical AND operator. || is a Logical OR operator. ! is a NOT operator. So, '&' is not a Logical operator. View Answer Workspace Report Discuss in Forum

2.

Which of the following cannot be checked in a switch-case statement? A. C. Character Float B. D. Integer enum

Answer & Explanation

Answer: Option C Explanation: The switch/case statement in the c language is defined by the language specification to use an int value, so you can not use a float value.

switch( expression ) { case constant-expression1: case constant-expression2: case constant-expression3: ... ... default : statements 4; }

statements 1; statements 2; statements3 ;

The value of the 'expression' in a switch-case statement must be an integer, char, short, long. Float and double are not allowed. View Answer Workspace Report Discuss in Forum

3.

How many times "IndiaBIX" is get printed?

#include<stdio.h>
int main() { int x; for(x=-1; x<=10; x++) { if(x < 5) continue; else break; printf("IndiaBIX"); } return 0; } A. C. Infinite times 0 times B. D. 11 times 10 times

Answer & Explanation

Answer: Option C Explanation: i. break statement "STOP's" executing the loop. ii. continue will execute the next instruction. 1st iteration : x = -1 process : if (x<5) [condition true] so "continue" executes and control goes to "else" where we break the loop and iterate again. So the statement actually never gets printed. View Answer Workspace Report Discuss in Forum

4.

How many times the while loop will get executed if a short int is 2 byte wide?

#include<stdio.h>
int main() { int j=1; while(j <= 255) { printf("%c %d\n", j, j); j++; } return 0; } 255 times

A.

Infinite times

B.

C.

256 times

D.

254 times

Answer & Explanation

Answer: Option B Explanation: The while(j <= 255) loop will get executed 255 times. The size short int(2 byte wide) does not affect the while() loop. View Answer Workspace Report Discuss in Forum

5.

Which is the correct order of mathematical operators ? A. B. C. D. Division, Multiplication, Modulus Division, Multiplication, Subtraction

Modulus, Addition, Division Addition, Division, Modulus, Subtraction

Answer & Explanation

Answer: Option B Explanation: Simply called as BODMAS (Bracket of Division, Multiplication, Addition and Subtraction).

C Programming :: Control Instructions


@ : Home > C Programming > Control Instructions > Find Output of Program

1.

What will be the output of the program?

#include<stdio.h>
int main() { int i=4; switch(i) { default: printf("This is default\n"); case 1: printf("This is case 1\n"); break; case 2: printf("This is case 2\n"); break; case 3:

printf("This is case 3\n"); } return 0; } This is default This is case 1 This is case 3 This is default

A.

B.

C.

This is case 1 This is case 3

D.

This is default

Answer & Explanation

Answer: Option A Explanation: In the very begining of switch-case statement default statement is encountered. So, it prints "This is default". In default statement there is no break; statement is included. So it prints thecase 1 statements. "This is case 1". Then the break; statement is encountered. Hence the program exits the switch-case statements. View Answer Workspace Report Discuss in Forum

2.

What will be the output of the program?

#include<stdio.h>
int main() { int x = 10, y = 20; if(!(!x) && x) printf("x = %d\n", x); else printf("y = %d\n", y); return 0; } A. C. y =20 x = 10 B. D. x=0 x=1

Answer & Explanation

Answer: Option C Explanation: The logical not operator takes expression and evaluates to true if the expression is false and evaluates to false if the expression is true. In other words it reverses the value of the expression.

Step Step Step Step Step

1: 2: 3: 3: 4:

if(!(!x) && x) if(!(!10) && 10) if(!(0) && 10) if(1 && 10) if(TRUE) here the if condition is satisfied. Hence it prints x = 10.

View Answer Workspace Report Discuss in Forum

3.

What will be the output of the program, if a short int is 2 bytes wide?

#include<stdio.h>
int main() { short int i = 0; for(i<=5 && i>=-1; ++i; i>0) printf("%u,", i); return 0; } 1 ... 65535

A.

B.

Expression syntax error

C.

No output

D.

0, 1, 2, 3, 4, 5

Answer & Explanation

Answer: Option A Explanation:

for(i<=5 && i>=-1; ++i; i>0) so expression i<=5 && i>=-1 initializes forloop. expression ++i is the loop condition. expression i>0 is the increment expression.
In for( i <= 5 && i >= -1; ++i; i>0) expression i<=5 && i>=-1 evaluates to one. Loop condition always get evaluated to true. Also at this point it increases i by one. An increment_expression i>0 has no effect on value of i.so for loop get executed till the limit of integer (ie. 65535) View Answer Workspace Report Discuss in Forum

4.

What will be the output of the program?

#include<stdio.h>
int main() { char ch; if(ch = printf("")) printf("It matters\n"); else printf("It doesn't matters\n");

return 0; } It doesn't matters

A.

It matters

B.

C.

matters

D.

No output

Answer & Explanation

Answer: Option B Explanation:

printf() returns the number of charecters printed on the console.


Step 1: if(ch = printf("")) here printf() does not print anything, so it returns '0'(zero). Step 2: if(ch = 0) here variable ch has the value '0'(zero). Step 3: if(0) Hence the if condition is not satisfied. So it prints the elsestatements. Hence the output is "It doesn't matters". View Answer Workspace Report Discuss in Forum

5.

What will be the output of the program?

#include<stdio.h>
int main() { int i = 1; switch(i) { printf("Hello\n"); case 1: printf("Hi\n"); break; case 2: printf("\nBye\n"); break; } return 0; } Hello Hi Hi Hello Bye Bye

A.

B.

C.

D.

Answer & Explanation

Answer: Option C Explanation:

switch(i) has the variable i it has the value '1'(one).


Then case 1: statements got executed. so, it prints "Hi". The break; statement make the program to be exited from switch-case statement.

switch-case do not execute any statements outside these blocks case anddefault
Hence the output is "Hi".

C Programming :: Control Instructions


@ : Home > C Programming > Control Instructions > Find Output of Program

6.

What will be the output of the program?

#include<stdio.h>
int main() { int a = 500, b = 100, c; if(!a >= 400) b = 300; c = 200; printf("b = %d c = %d\n", b, c); return 0; } A. b = 300 c = 200 B. b = 100 c = garbage b = 100 c = 200

C.

b = 300 c = garbage

D.

Answer & Explanation

Answer: Option D Explanation: Initially variables a = 500, b = 100 and c is not assigned. Step Step Step Step Step Step 1: 2: 3: 4: 5: 6:

if(!a >= 400) if(!500 >= 400) if(0 >= 400) if(FALSE) Hence the if condition is failed. variable c is assigned to a value '500'. printf("b = %d c = %d\n", b, c); It prints value of b and c.

Hence the output is "b = 100 c = 200" View Answer Workspace Report Discuss in Forum

7.

What will be the output of the program?

#include<stdio.h>
int main() { int i = 5; while(i-- >= 0) printf("%d,", i); i = 5; printf("\n"); while(i-- >= 0) printf("%i,", i); while(i-- >= 0) printf("%d,", i); return 0; } 4, 3, 2, 1, 0, -1 4, 3, 2, 1, 0, -1 5, 4, 3, 2, 1, 0 5, 4, 3, 2, 1, 0 5, 4, 3, 2, 1, 0 5, 4, 3, 2, 1, 0 5, 4, 3, 2, 1, 0

A.

B.

C.

Error

D.

Answer & Explanation

Answer: Option A Explanation: Step 1: Initially the value of variable i is '5'. Loop 1: while(i-- >= 0) here i = 5, this statement becomes while(5-- >= 0)Hence the while condition is satisfied and it prints '4'. (variable 'i' is decremented by '1'(one) in previous while condition) Loop 2: while(i-- >= 0) here i = 4, this statement becomes while(4-- >= 0)Hence the while condition is satisfied and it prints '3'. (variable 'i' is decremented by '1'(one) in previous while condition) Loop 3: while(i-- >= 0) here i = 3, this statement becomes while(3-- >= 0)Hence the while condition is satisfied and it prints '2'. (variable 'i' is decremented by '1'(one) in previous while condition) Loop 4: while(i-- >= 0) here i = 2, this statement becomes while(2-- >= 0)Hence the while condition is satisfied and it prints '1'. (variable 'i' is decremented by '1'(one) in previous while condition) Loop 5: while(i-- >= 0) here i = 1, this statement becomes while(1-- >= 0)Hence the while condition is satisfied and it prints '0'. (variable 'i' is decremented by '1'(one) in previous while condition) Loop 6: while(i-- >= 0) here i = 0, this statement becomes while(0-- >= 0)Hence the while condition is satisfied and it prints '-1'. (variable 'i' is decremented by '1'(one) in previous while condition) Loop 7: while(i-- >= 0) here i = -1, this statement becomes while(-1-- >= 0) Hence the while condition is not satisfied and loop exits. The output of first while loop is 4,3,2,1,0,-1 Step 2: Then the value of variable i is initialized to '5' Then it prints a new line character(\n).

See the above Loop 1 to Loop 7 . The output of second while loop is 4,3,2,1,0,-1 Step 3: The third while loop, while(i-- >= 0) here i = -1(because the variable'i' is decremented to '-1' by previous while loop and it never initialized.). This statement becomes while(-1-- >= 0) Hence the while condition is not satisfied and loop exits. Hence the output of the program is 4,3,2,1,0,-1 4,3,2,1,0,-1 View Answer Workspace Report Discuss in Forum

8.

What will be the output of the program?

#include<stdio.h>
int main() { unsigned int i = 65536; /* Assume 2 byte integer*/ while(i != 0) printf("%d",++i); printf("\n"); return 0; } A. C. Infinite loop 0 1 2 ... 32767 - 32766 -32765 -1 0 B. D. 0 1 2 ... 65535 No output

Answer & Explanation

Answer: Option D Explanation: Here unsigned int size is 2 bytes. It varies from 0,1,2,3, ... to 65535. Step 1:unsigned int i = 65536; here variable i becomes '0'(zero). becauseunsigned int varies from 0 to 65535. Step 2: while(i != 0) this statement becomes while(0 != 0). Hence thewhile(FALSE) condition is not satisfied. So, the inside the statements of whileloop will not get executed. Hence there is no output. View Answer Workspace Report Discuss in Forum

9.

What will be the output of the program?

#include<stdio.h>
int main() { unsigned int i = 65535; /* Assume 2 byte integer*/ while(i++ != 0) printf("%d",++i); printf("\n"); return 0; } A. C. Infinite loop B. D. 0 1 2 ... 65535 No output

0 1 2 ... 32767 - 32766 -32765 -1 0

Answer & Explanation

Answer: Option A Explanation: Here unsigned int size is 2 bytes. It varies from 0,1,2,3, ... to 65535. Step 1:unsigned int i = 65535; Step 2: Loop 1: while(i++ != 0) this statement becomes while(65535 != 0). Hence the while(TRUE) condition is satisfied. Then the printf("%d", ++i); prints '1'(variable 'i' is already increemented by '1' in while statement and now increemented by '1' in printf statement) Loop 2: while(i++ != 0) this statement becomes while(1 != 0). Hence the while(TRUE) condition is satisfied. Then theprintf("%d", ++i); prints '3'(variable 'i' is already increemented by '1' in while statement and now increemented by '1' in printf statement) .... .... The while loop will never stops executing, because variable i will never become '0'(zero). Hence this is called 'Infinite loop'. View Answer Workspace Report Discuss in Forum

10. What will be the output of the program?

#include<stdio.h>
int main() { char str[]="C-program"; int a = 5; printf(a >10?"Ps\n":"%s\n", str); return 0; } A. C-program B. C-program

C.

Error

D.

None of above

Answer & Explanation

Answer: Option A Explanation: Step 1: char str[]="C-program"; here variable str contains "C-program". Step 2: int a = 5; here variable a contains "5". Step 3: printf(a >10?"Ps\n":"%s\n", str); this statement can be written as

if(a > 10) { printf("Ps\n"); } else { printf("%s\n", str); }


Here we are checking a > 10 means 5 > 10. Hence this condition will be failed. So it prints variable str. Hence the output is "C-program".

11. What will be the output of the program?

#include<stdio.h>
int main() { int a = 300, b, c; if(a >= 400) b = 300; c = 200; printf("%d, %d, %d\n", a, b, c); return 0; } A. C. 300, 300, 200 300, Garbage, 200 B. D. Garbage, 300, 200 300, 300, Garbage

Answer & Explanation

Answer: Option C Explanation:

Step 1: int a = 300, b, c; here variable a is initialized to '300', variable b and c are declared, but not initialized. Step 2: if(a >= 400) means if(300 >= 400). Hence this condition will be failed. Step 3: c = 200; here variable c is initialized to '200'. Step 4: printf("%d, %d, %d\n", a, b, c); It prints "300, garbage value, 200". because variable b is not initialized. View Answer Workspace Report Discuss in Forum

12. What will be the output of the program?

#include<stdio.h>
int main() { float a = 0.7; if(0.7 > a) printf("Hi\n"); else printf("Hello\n"); return 0; } A. C. Hi B. D. Hello None of above

Hi Hello

Answer & Explanation

Answer: Option A Explanation:

if(0.7 > a) here a is a float variable and 0.7 is a double constant. The double constant 0.7 is greater than the float variable a. Hence the if condition is satisfied and it prints 'Hi'
Example:

#include<stdio.h> int main() { float a=0.7; printf("%.10f %.10f\n",0.7, a); return 0; }


Output: 0.7000000000 0.6999999881 View Answer Workspace Report Discuss in Forum

13. What will be the output of the program?

#include<stdio.h>
int main() { int x, y, z; x=y=z=1; z = ++x || ++y && ++z; printf("x=%d, y=%d, z=%d\n", x, y, z); return 0; } A. C. x=2, y=1, z=1 B. D. x=2, y=2, z=1 x=1, y=2, z=1

x=2, y=2, z=2

Answer & Explanation

Answer: Option A Explanation: Step 1: x=y=z=1; here the variables x ,y, z are initialized to value '1'. Step 2: z = ++x || ++y && ++z; becomes z = ( (++x) || (++y && ++z) ). Here + +x becomes 2. So there is no need to check the other side because ||(Logical OR) condition is satisfied.(z = (2 || ++y && ++z)). There is no need to process ++y && ++z. Hence it returns '1'. So the value of variable z is '1' Step 3: printf("x=%d, y=%d, z=%d\n", x, y, z); It prints "x=2, y=1, z=1". here x is increemented in previous step. y and z are not increemented. View Answer Workspace Report Discuss in Forum

14. What will be the output of the program?

#include<stdio.h>
int main() { int i=3; switch(i) { case 1: printf("Hello\n"); case 2: printf("Hi\n"); case 3: continue; default: printf("Bye\n"); } return 0; } A. C. Error: Misplaced continue B. D. Bye Hello Hi

No output

Answer & Explanation

Answer: Option A Explanation: The keyword continue cannot be used in switch case. It must be used in for orwhile or do while loop. If there is any looping statement in switch case then we can use continue. View Answer Workspace Report Discuss in Forum

15. What will be the output of the program?

#include<stdio.h>
int main() { int k, num = 30; k = (num < 10) ? 100 : 200; printf("%d\n", num); return 0; } A. C. 200 100 B. D. 30

500

Answer & Explanation

Answer: Option B Explanation: Step 1: int k, num = 30; here the variable k and num is declared as integer type and num is initialized to 30. Step 2: k = (num > (num < 10 ? 100 : 200) : 500); This statement does not affect the output. Let's skip this step. Step 3: printf("%d\n", num); It prints the value of variable num. Hence the output is "30".

16. What will be the output of the program?

#include<stdio.h>
int main() { int x = 3; float y = 3.0; if(x == y) printf("x and y are equal"); else printf("x and y are not equal"); return 0; }

A. C.

x and y are equal

B. D.

x and y are not equal No output

Unpredictable

Answer & Explanation

Answer: Option A Explanation: Step 1: int x = 3; here variable x is an integer type and initialized to '3'. Step 2: float y = 3.0; here variable y is an float type and initialized to '3.0' Step 3: if(x == y) here we are comparing if(3 == 3.0) hence this condition is satisfied. Hence it prints "x and y are equal". View Answer Workspace Report Discuss in Forum

17. What will be the output of the program?

#include<stdio.h>
int main() { int a=0, b=1, c=3; *((a) ? &b : &a) = a ? b : c; printf("%d, %d, %d\n", a, b, c); return 0; } A. 0, 1, 3 3, 1, 3 B. 1, 2, 3

C.

D.

1, 3, 1

Answer & Explanation

Answer: Option C Explanation: Step 1: int a=0, b=1, c=3; here variable a, b, and c are declared as integer type and initialized to 0, 1, 3 respectively. Step 2: *((a) ? &b : &a) = a ? b : c; The right side of the expression(a? b:c) becomes (0?1:3). Hence it return the value '3'. The left side of the expression *((a) ? &b : &a) becomes *((0) ? &b : &a). Hence this contains the address of the variable a *(&a). Step 3: *((a) ? &b : &a) = a ? b : c; Finally this statement becomes *(&a)=3. Hence the variable a has the value '3'.

Step 4: printf("%d, %d, %d\n", a, b, c); It prints "3, 1, 3". View Answer Workspace Report Discuss in Forum

18. What will be the output of the program?

#include<stdio.h>
int main() { int i=0; for(; i<=5; i++); printf("%d,", i); return 0; } A. C. 0, 1, 2, 3, 4, 5 1, 2, 3, 4 B. D. 5 6

Answer & Explanation

Answer: Option D Explanation: Step 1: int i = 0; here variable i is an integer type and initialized to '0'. Step 2: for(; i<=5; i++); variable i=0 is already assigned in previous step. The semicolon at the end of this for loop tells, "there is no more statement is inside the loop". Loop 1: here i=0, the condition in for(; 0<=5; i++) loop satisfies and then i is increemented by '1'(one) Loop 2: here i=1, the condition in for(; 1<=5; i++) loop satisfies and then i is increemented by '1'(one) Loop 3: here i=2, the condition in for(; 2<=5; i++) loop satisfies and then i is increemented by '1'(one) Loop 4: here i=3, the condition in for(; 3<=5; i++) loop satisfies and then i is increemented by '1'(one) Loop 5: here i=4, the condition in for(; 4<=5; i++) loop satisfies and then i is increemented by '1'(one) Loop 6: here i=5, the condition in for(; 5<=5; i++) loop satisfies and then i is increemented by '1'(one) Loop 7: here i=6, the condition in for(; 6<=5; i++) loop fails and then i is not increemented. Step 3: printf("%d,", i); here the value of i is 6. Hence the output is '6'. View Answer Workspace Report Discuss in Forum

19. What will be the output of the program?

#include<stdio.h>

int main() { char j=1; while(j < 5) { printf("%d, ", j); j = j+1; } printf("\n"); return 0; } A. B. C. D. 1 2 3 ... 127 1 2 3 ... 255 1 2 3 ... 127 128 0 1 2 3 ... infinite times 1, 2, 3, 4

Answer & Explanation

Answer: Option D Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

20. What will be the output of the program?

#include<stdio.h>
int main() { int x=1, y=1; for(; y; printf("%d %d\n", x, y)) { y = x++ <= 5; } printf("\n"); return 0; } 2 3 4 5 6 7 1 1 1 1 1 0

A.

B.

2 3 4 5 6

1 1 1 1 1

C.

21 31 41

D.

22 33 44

51
Answer & Explanation

55

Answer: Option A Explanation: No answer description available for this question.

C Programming :: Control Instructions


@ : Home > C Programming > Control Instructions > Point Out Errors

1.

Point out the error, if any in the for loop.

#include<stdio.h>
int main() { int i=1; for(;;) { printf("%d\n", i++); if(i>10) break; } return 0; } A. B. C. D. There should be a condition in the for loop The two semicolons should be dropped The for loop should be replaced with while loop. No error

Answer & Explanation

Answer: Option D Explanation: Step 1: for(;;) this statement will genereate infinite loop. Step 2: printf("%d\n", i++); this statement will print the value of variable iand increement i by 1(one). Step 3: if(i>10) here, if the variable i value is greater than 10, then the for loop breaks.

Hence the output of the program is 0 1 2 3 4 5 6 7 8 9 10 View Answer Workspace Report Discuss in Forum

2.

Point out the error, if any in the while loop.

#include<stdio.h>
int main() { int i=1; while() { printf("%d\n", i++); if(i>10) break; } return 0; } A. B. C. D. There should be a condition in the while loop

There should be at least a semicolon in the while The while loop should be replaced with for loop. No error

Answer & Explanation

Answer: Option A Explanation: The while() loop must have conditional expression or it shows "Expression syntax" error. Example: while(i > 10){ ... } View Answer Workspace Report Discuss in Forum

3.

Point out the error, if any in the while loop.

#include<stdio.h>
int main() { void fun(); int i = 1; while(i <= 5) { printf("%d\n", i); if(i>2) goto here; } return 0; } void fun() { here: printf("It works"); } A. B. C. D. No Error: prints "It works" Error: fun() cannot be accessed Error: goto cannot takeover control to other function

No error

Answer & Explanation

Answer: Option C Explanation: A label is used as the target of a goto statement, and that label must be within the same function as the goto statement. Syntax: goto <identifier> ; Control is unconditionally transferred to the location of a local label specified by <identifier>. Example:

#include <stdio.h> int main() { int i=1; while(i>0) { printf("%d", i++); if(i==5) goto mylabel; } mylabel: return 0; }

Output: 1,2,3,4 View Answer Workspace Report Discuss in Forum

4.

Which of the following errors would be reported by the compiler on compiling the program given below?

#include<stdio.h>
int main() { int a = 5; switch(n) { case 1: ...... case 2: ...... case 3, 5: ...... case a: ...... } return 0; } A. B. C. D. Variables cannot be checked using a switch as in a case a. Expression as in case 3, 5 is not allowed. All cases in switch are not unique.

There is no break statement in each case.

Answer & Explanation

Answer: Option C Explanation: Comma operator always return right most expression ( here integer ). So, case 1 will return 1 case 2 will return 2 case 3,5 will return 5 case 4 will return 4 case 5 will return 5 Since here two case has 5 but case must be unique. View Answer Workspace Report Discuss in Forum

5.

Point out the error, if any in the program.

#include<stdio.h>
int main()

{ int i = 4, j = 2; switch(i) { case 1: printf("Case1"); break; case j: printf("Case2"); break; } return 0; } A. B. C. D. Error: No default specified Error: variable j cannot be used like case j

Error: in switch statement No Error: Nothing will print

Answer & Explanation

Answer: Option B Explanation: The compiler reports the error "Constant Expression required" in the line case j: , because we cannot use the variable with case keyword.

C Programming :: Control Instructions


@ : Home > C Programming > Control Instructions > Point Out Errors

6.

Point out the error, if any in the program.

#include<stdio.h>
int main() { int i = 1; switch(i) { case 1: printf("Case1"); break; case 1*2+4: printf("Case2"); break; } return 0; }

A. B. C. D.

Error: in case 1*2+4 statement Error: No default specified Error: in switch statement No Error

Answer & Explanation

Answer: Option D Explanation: Constant expression are accepted in switch It prints "Case1" View Answer Workspace Report Discuss in Forum

7.

Point out the error, if any in the program.

#include<stdio.h>
int main() { int a = 10; switch(a) { } printf("This is c program."); return 0; } A. B. C. D. Error: No case statement specified Error: No default specified No Error

Error: infinite loop occurs

Answer & Explanation

Answer: Option C Explanation: There can exists a switch statement, which has no case View Answer Workspace Report Discuss in Forum

8.

Point out the error, if any in the program.

#include<stdio.h>
int main() { int i = 1; switch(i) { printf("This is c program."); case 1: printf("Case1"); break; case 2: printf("Case2"); break; } return 0; } A. B. C. D. Error: No default specified Error: Invalid printf statement after switch statement No Error and prints "Case1"

None of above

Answer & Explanation

Answer: Option C Explanation:

switch(i) becomes switch(1), then the case 1: block is get executed. Hence it prints
"Case1".

printf("This is c program."); is ignored by the compiler.


Hence there is no error and prints "Case1". View Answer Workspace Report Discuss in Forum

9.

Point out the error, if any in the program.

#include<stdio.h>
int main() { int a = 10, b; a >=5 ? b=100; b=200 printf("%d\n", b); return 0; } A. 100 B. 200

C.

Error: L value required for b

D.

Garbage value

Answer & Explanation

Answer: Option C Explanation: variable b is not assigned

C Programming :: Control Instructions


@ : Home > C Programming > Control Instructions > Point Out Correct Statements

1.

Which of the following statements are correct about an if-else statements in a C-program? 1: Every if-else statement can be replaced by an equivalent statements using

? ; operators
2: Nested if-else statements are allowed. 3: Multiple statements in an if block are allowed. 4: Multiple statements in an else block are allowed.

A.

1 and 2

B.

2 and 3 2, 3, 4

C.

1, 2 and 4

D.

Answer & Explanation

Answer: Option D Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

2.

Which of the following statements are correct about the below C-program?

#include<stdio.h>
int main()

{ int x = 10, y = 100%90, i; for(i=1; i<10; i++) if(x != y); printf("x = %d y = %d\n", x, y) return 0; } 1 : The printf() function is called 10 times. 2 : The program will produce the output x = 10 y = 10 3 : The ; after the if(x!=y) will NOT produce an error. 4 : The program will not produce output. 2, 3

A. C.

1 1, 4

B. D.

2, 3, 4

Answer & Explanation

Answer: Option B Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

3.

Which of the following statements are correct about the program?

#include<stdio.h>
int main() { int x = 30, y = 40; if(x == y) printf("x is equal to y\n"); else if(x > y) printf("x is greater than y\n"); else if(x < y) printf("x is less than y\n") return 0; } A. C. Error: Statement missing B. D. Error: Expression syntax Error: Rvalue required

Error: Lvalue required

Answer & Explanation

Answer: Option A

Explanation: This program will result in error "Statement missing ;"

printf("x is less than y\n") here ; is added to the end of this statement.
View Answer Workspace Report Discuss in Forum

4.

Point out the correct statements are correct about the program below?

#include<stdio.h>
int main() { char ch; while(x=0;x<=255;x++) printf("ASCII value of %d character %c\n", x, x); return 0; } A. B. C. D. The code generates an infinite loop The code prints all ASCII values and its characters Error: x undeclared identifier Error: while statement missing

Answer & Explanation

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. View Answer Workspace Report Discuss in Forum

5.

Which of the following sentences are correct about a for loop in a C program? 1: for loop works faster than a while loop. 2: All things that can be done using a for loop can also be done using a whileloop. 3: for(;;) implements an infinite loop. 4: for loop can be used if we want statements in a loop get executed at least once.

A.

B.

1, 2

C.

2, 3

D.

2, 3, 4

Answer & Explanation

Answer: Option D Explanation: No answer description available for this question.

6.

Which of the following statements are correct about the below program?

#include<stdio.h>
int main() { int i = 10, j = 20; if(i = 5) && if(j = 10) printf("Have a nice day"); return 0; } A. B. C. D. Output: Have a nice day No output Error: Expression syntax

Error: Undeclared identifier if

Answer & Explanation

Answer: Option C Explanation: "Expression syntax" error occur in this line if(i = 5) && if(j = 10). because we cannot use two if to compare. View Answer Workspace Report Discuss in Forum

7.

Which of the following statements are correct about the below program?

#include<stdio.h>
int main() { int n = 0, y = 1; y == 1?n=0:n=1; if(n)

printf("Yes\n"); else printf("No\n"); return 0; } A. B. C. D. Error: Declaration terminated incorrectly Error: Syntax error Error: Lvalue required

None of above

Answer & Explanation

Answer: Option C Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

8.

Which of the following sentences are correct about a switch loop in a C program? 1: switch is useful when we wish to check the value of variable against a particular set of values. 2: switch is useful when we wish to check whether a value falls in different ranges. 3: Compiler implements a jump table for cases used in switch. 4: It is not necessary to use a break in every switch statement. 1,3,4

A. C.

1,2 2,4

B. D.

Answer & Explanation

Answer: Option B Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

9.

Which of the following statements are correct about the below program?

#include<stdio.h>
int main() { int i = 0; i++; if(i <= 5) { printf("IndiaBIX\n"); exit(); main(); } return 0; } A. B. C. D. The program prints 'IndiaBIX' 5 times The program prints 'IndiaBIX' one time

The call to main() after exit() doesn't materialize. The compiler reports an error since main() cannot call itself.

Answer & Explanation

Answer: Option B Explanation: Step 1: int i = 0; here variable i is declared as an integer type and initialized to '0'(zero). Step 2: i++; here variable i is increemented by 1(one). Hence, i = 1 Step 3: if(i <= 5) becomes if(1 <= 5) here we are checking '1' is less than or equal to '5'. Hence the if condition is satisfied. Step 4: printf("IndiaBIX\n"); It prints "IndiaBIX" Step 5: exit(); terminates the program execution. Hence the output is "IndiaBIX". View Answer Workspace Report Discuss in Forum

10. Which of the following statements are correct about the below program?

#include<stdio.h>
int main() { int i = 10, j = 15; if(i % 2 = j % 3) printf("IndiaBIX\n"); return 0; } A. C. Error: Expression syntax Error: Rvalue required B. D. Error: Lvalue required

The Code runs successfully

Answer & Explanation

Answer: Option B Explanation:

if(i % 2 = j % 3) This statement generates "LValue required error". There is no variable on the left side of the expression to assign (j % 3).

C Programming :: Control Instructions


@ : Home > C Programming > Control Instructions > True / False Questions

1.

The modulus operator cannot be used with a long double. A. True B. False

Answer & Explanation

Answer: Option A Explanation:

fmod(x,y) - Calculates x modulo y, the remainder of x/y. This function is the same as the modulus operator. But fmod() performs floating point or long double divisions.
View Answer Workspace Report Discuss in Forum

2.

A char variable can store either an ASCII character or a Unicode character. A. True B. False

Answer & Explanation

Answer: Option A Explanation: Yes, we can store either an ASCII character or a Unicode character in a char variable. View Answer Workspace Report Discuss in Forum

3.

If scanf() is used to store a value in a char variable then along with the value a carriage return(\r) also gets stored it. A. True B. Fals e

Answer & Explanation

Answer: Option B Explanation: No, the carriage return tells the compiler to read the input from the buffer after ENTER key is pressed. View Answer Workspace Report Discuss in Forum

4.

A short integer is at least 16 bits wide and a long integer is at least 32 bits wide. A. True B. False

Answer & Explanation

Answer: Option A Explanation: The basic C compiler is 16 bit compiler, below are the size of it's data types The size of short int is 2 bytes wide(16 bits). The size of long int is 4 bytes wide(32 bits).

1.

By default, the data type of a constant without a decimal point is int, whereas the one with a decimal point is a double. A. Yes B. No

Answer & Explanation

Answer: Option A Explanation:

6 is int constant. 6.68 is double. 6.68L is long double constant. 6.68f is float constant.
View Answer Workspace Report Discuss in Forum

2.

Can we use a switch statement to switch on strings? A. Yes B. No

Answer & Explanation

Answer: Option B Explanation:

The cases in a switch must either have integer constants or constant expressions. View Answer Workspace Report Discuss in Forum

3.

We want to test whether a value lies in the range 2 to 4 or 5 to 7. Can we do this using a switch? A. Yes B. No

Answer & Explanation

Answer: Option A Explanation: We can do this in following switch statement

switch(a) { case 2: case 3: case 4: /* some statements */ break; case 5: case 6: case 7: /* some statements */ break; }
View Answer Workspace Report Discuss in Forum

4.

The way the break is used to take control out of switch can continue to take control of the beginning of the switch? A. Yes B. No

Answer & Explanation

Answer: Option B Explanation:

continue can work only with loops and not with switch

C Programming :: Expressions
@ : Home > C Programming > Expressions > General Questions

1.

In which order do the following gets evaluated 1. Relational 2. Arithmetic 3. Logical 4. Assignment 2134

A. C.

B. D.

1234 3214

4321

Answer & Explanation

Answer: Option A Explanation: 1. 2. 3. 4. Arithmetic operators: *, /, %, +, Relational operators: >, <, >=, <=, ==, != Logical operators : !, &&, || Assignment operators: =

View Answer Workspace Report Discuss in Forum

2.

Which of the following are unary operators in C? 1. ! 2. sizeof 3. ~ 4. &&

A.

1, 2

B.

1, 3 1, 2, 3

C.

2, 4

D.

Answer & Explanation

Answer: Option D Explanation:

An operation with only one operand is called unary operation. Unary operators: ! Logical NOT operator. ~ bitwise NOT operator. sizeof Size-of operator.

&& Logical AND is a logical operator.


Therefore, 1, 2, 3 are unary operators. View Answer Workspace Report Discuss in Forum

3.

Which of the following is the correct order if calling functions in the below code?

a = f1(23, 14) * f2(12/4) + f3();


A. B. C. D. f1, f2, f3 f3, f2, f1 Order may vary from compiler to compiler

None of above

Answer & Explanation

Answer: Option C Explanation: Here, Multiplication will happen before the addition, but in which order the functions would be called is undefined. In an arithmetic expression the parenthesis tell the compiler which operands go with which operators but do not force the compiler to evaluate everything within the parenthesis first. View Answer Workspace Report Discuss in Forum

4.

Which of the following is the correct usage of conditional operators used in C? A. a>b ? c=30 : c=40; max = a>b ? a>c?a:c:b>c? b:c B. a>b ? c=30;

C.

D.

return (a>b?a:b)

Answer & Explanation

Answer: Option C Explanation: No answer description available for this question.

View Answer Workspace Report Discuss in Forum

5.

Which of the following correctly shows the hierarchy of arithmetic operations in C? A. C. /*B. D. *-/ */-

-/*

Answer & Explanation

Answer: Option A Explanation: Simply called as BODMAS (Bracket of Division, Multiplication, Addition and Subtraction).

6.

Which of the following is the correct order of evaluation for the below expression?

z = x y * z / 4 % 2 - 1
A. C. */%-= B. D. =*/%*%/-=

/*%-=

Answer & Explanation

Answer: Option A Explanation: No answer description available for this question.

C Programming :: Expressions
@ : Home > C Programming > Expressions > Find Output of Program

C Programming :: Expressions
@ : Home > C Programming > Expressions > Find Output of Program

1.

What will be the output of the program?

#include<stdio.h>
int main() { static int a[20]; int i = 0;

a[i] = i ; printf("%d, %d, %d\n", a[0], a[1], i); return 0; } A. 1, 0, 1 0, 0, 0 B. 1, 1, 1

C.

D.

0, 1, 0

Answer & Explanation

Answer: Option C Explanation: Step 1: static int a[20]; here variable a is declared as an integer type andstatic. If a variable is declared as static and it will ne automatically initialized to value '0'(zero). Step 2: int i = 0; here vaiable i is declared as an integer type and initialized to '0'(zero). Step 3: a[i] = i ; becomes a[0] = 0; Step 4: printf("%d, %d, %d\n", a[0], a[1], i); Here a[0] = 0, a[1] = 0(because all staic variables are initialized to '0') and i = 0. Step 4: Hence the output is "0, 0, 0". View Answer Workspace Report Discuss in Forum

2.

What will be the output of the program?

#include<stdio.h>
int main() { int i=3; i = i++; printf("%d\n", i); return 0; } A. C. 3 5 B. D. 4

Answer & Explanation

Answer: Option B Explanation: Step 1: int i=3; here variable i is declared as an integer type and initialized to value '3'. Step 2: i = i++; variable i is increemented by '1'(one) and assigned to variable i(i=4). Step 3: printf("%d\n", i); prints the value of variable i. Step 4: Hence the output is '4'.

View Answer Workspace Report Discuss in Forum

3.

What will be the output of the program?

#include<stdio.h>
int main() { int i=2; printf("%d, %d\n", ++i, ++i); return 0; } A. 3, 4 B. 4, 3 Output may vary from compiler to compiler

C.

4, 4

D.

Answer & Explanation

Answer: Option D Explanation: The order of evaluation of arguments passed to a function call is unspecified. Anyhow, we consider ++i, ++i are Right-to-Left associativity. The output of the program is 4,3 View Answer Workspace Report Discuss in Forum

4.

What will be the output of the program?

#include<stdio.h>
int main() { int x=4, y, z; y = --x; z = x--; printf("%d, %d, %d\n", x, y, z); return 0; } A. 4, 3, 3 B. 4, 3, 2 2, 3, 3

C.

3, 3, 2

D.

Answer & Explanation

Answer: Option D

Explanation: Step 1: int x=4, y, z; here variable x, y, z are declared as an integer type and variable x is initialized to 4. Step 2: y = --x; becomes y = 3; because (--x) is pre-increement operator. Step 3: z = x--; becomes z = 3;. In the next step variable x becomes 2, because (x--) is post-increement operator. Step 4: printf("%d, %d, %d\n", x, y, z); Hence it prints "2, 3, 3". View Answer Workspace Report Discuss in Forum

5.

What will be the output of the program?

#include<stdio.h>
int main() { char ch; ch = 'A'; printf("The letter is"); printf("%c", ch >= 'A' && ch <= 'Z' ? ch + 'a' - 'A':ch); printf("Now the letter is"); printf("%c\n", ch >= 'A' && ch <= 'Z' ? ch : ch + 'a' - 'A'); return 0; } The letter is a Now the letter is A The letter is A Now the letter is a None of above

A.

B.

C.

Error

D.

Answer & Explanation

Answer: Option A Explanation: Step 1: char ch; ch = 'A'; here variable ch is declared as an character type an initialized to 'A'. Step 2: printf("The letter is"); It prints "The letter is". Step 3: printf("%c", ch >= 'A' && ch <= 'Z' ? ch + 'a' - 'A':ch); The ASCII value of 'A' is 65 and 'a' is 97. Here => ('A' >= 'A' && 'A' <= 'Z') ? (A + 'a' - 'A'):('A') => (TRUE && TRUE) ? (65 + 97 - 65) : ('A')

=> (TRUE) ? (97): ('A') In printf the format specifier is '%c'. Hence prints 97 as 'a'. Step 4: printf("Now the letter is"); It prints "Now the letter is". Step 5: printf("%c\n", ch >= 'A' && ch <= 'Z' ? ch : ch + 'a' - 'A'); Here => ('A' >= 'A' && 'A' <= 'Z') ? ('A') : (A + 'a' - 'A') => (TRUE && TRUE) ? ('A') :(65 + 97 - 65) => (TRUE) ? ('A') : (97) It prints 'A' Hence the output is The letter is a Now the letter is A

6.

What will be the output of the program?

#include<stdio.h>
int main() { int i=-3, j=2, k=0, m; m = ++i && ++j || ++k; printf("%d, %d, %d, %d\n", i, j, k, m); return 0; } A. 1, 2, 0, 1 -2, 3, 0, 1 B. -3, 2, 0, 1

C.

D.

2, 3, 1, 1

Answer & Explanation

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". View Answer Workspace Report Discuss in Forum

7.

What will be the output of the program?

#include<stdio.h>
int main() { int i=-3, j=2, k=0, m; m = ++i || ++j && ++k; printf("%d, %d, %d, %d\n", i, j, k, m); return 0; } A. 2, 2, 0, 1 B. 1, 2, 1, 0 -2, 2, 0, 1

C.

-2, 2, 0, 0

D.

Answer & Explanation

Answer: Option D 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; here (++j && ++k;) this code will not get executed because ++i has non-zero value. becomes m = -2 || ++j && ++k; becomes m = TRUE || ++j && ++k; 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 variable 'i' only increemented by '1'(one). The variable j,k are not increemented. Hence the output is "-2, 2, 0, 1". View Answer Workspace Report Discuss in Forum

8.

What will be the output of the program?

#include<stdio.h>

int main() { int i=-3, j=2, k=0, m; m = ++i && ++j && ++k; printf("%d, %d, %d, %d\n", i, j, k, m); return 0; } -2, 3, 1, 1

A.

B.

2, 3, 1, 2

C.

1, 2, 3, 1

D.

3, 3, 1, 2

Answer & Explanation

Answer: Option A 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 && 1; becomes m = TRUE && 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,k are increemented by '1'(one). Hence the output is "-2, 3, 1, 1". View Answer Workspace Report Discuss in Forum

9.

What will be the output of the program?

#include<stdio.h>
int main() { int i=2; int j = i + (1, 2, 3, 4, 5); printf("%d\n", j); return 0; } A. C. 4 6 B. D. 7

Answer & Explanation

Answer: Option B

Explanation: Because, comma operator used in the expression i (1, 2, 3, 4, 5). The comma operator has left-right associativity. The left operand is always evaluated first, and the result of evaluation is discarded before the right operand is evaluated. In this expression 5 is the right most operand, hence after evaluating expression (1, 2, 3, 4, 5) the result is 5, which on adding to i results into 7. View Answer Workspace Report Discuss in Forum

10. What will be the output of the program?

#include<stdio.h>
int main() { int x=55; printf("%d, %d, %d\n", x<=55, x=40, x>=10); return 0; } A. C. 1, 40, 1 B. D. 1, 55, 1 1, 1, 1

1, 55, 0

Answer & Explanation

Answer: Option A Explanation: Step 1: int x=55; here variable x is declared as an integer type and initialized to '55'. Step 2: printf("%d, %d, %d\n", x<=55, x=40, x>=10); here x<=55 returns TRUE hence it prints '1'. x=40 here x is assigned to 40 Hence it prints '40'. x>=10 returns TRUE. hence it prints '1'. Step 3: Hence the output is "1, 40, 1".

11. What will be the output of the program?

#include<stdio.h>
int main() { int k, num=30; k = (num>5 ? (num <=10 ? 100 : 200): 500); printf("%d\n", num); return 0; } A. C. 200 100 B. D. 30

500

Answer & Explanation

Answer: Option B Explanation: Step 1: int k, num=30; here variable k and num are declared as an integer type and variable num is initialized to '30'. Step 2: k = (num>5 ? (num <=10 ? 100 : 200): 500); This statement does not affect the output of the program. Because we are going to print the variablenum in the next statement. So, we skip this statement. Step 3: printf("%d\n", num); It prints the value of variable num '30' Step 3: Hence the output of the program is '30' View Answer Workspace Report Discuss in Forum

12. What will be the output of the program?

#include<stdio.h>
int main() { int a=100, b=200, c; c = (a == 100 || b > 200); printf("c=%d\n", c); return 0; } A. C. c=100 c=1 B. D. c=200 c=300

Answer & Explanation

Answer: Option C Explanation: Step 1: int a=100, b=200, c; Step 2: c = (a == 100 || b > 200); becomes c = (100 == 100 || 200 > 200); becomes c = (TRUE || FALSE); becomes c = (TRUE);(ie. c = 1) Step 3: printf("c=%d\n", c); It prints the value of variable i=1 Hence the output of the program is '1'(one). View Answer Workspace Report Discuss in Forum

13. What will be the output of the program?

#include<stdio.h>
int main() {

int x=12, y=7, z; z = x!=4 || y == 2; printf("z=%d\n", z); return 0; } A. C. z=0 z=4 B. D. z=1

z=2

Answer & Explanation

Answer: Option B Explanation: Step 1: int x=12, y=7, z; here variable x, y and z are declared as an integer and variable x and y are initialized to 12, 7 respectively. Step 2: z = x!=4 || y == 2; becomes z = 12!=4 || 7 == 2; then z = TRUE || FALSE; Hence it returns TRUE. So the value of z=1. Step 3: printf("z=%d\n", z); Hence the output of the program is "z=1". View Answer Workspace Report Discuss in Forum

14. What will be the output of the program?

#include<stdio.h>
int main() { int i=4, j=-1, k=0, w, x, y, z; w = i || j || k; x = i && j && k; y = i || j &&k; z = i && j || k; printf("%d, %d, %d, %d\n", w, x, y, z); return 0; } A. C. 1, 1, 1, 1 1, 0, 0, 1 B. D. 1, 1, 0, 1 1, 0, 1, 1

Answer & Explanation

Answer: Option D Explanation: Step 1: int i=4, j=-1, k=0, w, x, y, z; here variable i, j, k, w, x, y, z are declared as an integer type and the variable i, j, k are initialized to 4, -1, 0 respectively.

Step 2: w = i || j || k; becomes w = 4 || -1 || 0;. Hence it returns TRUE. So, w=1 Step 3: x = i && j && k; becomes x = 4 && -1 && 0; Hence it returns FALSE. So, x=0 Step 4: y = i || j &&k; becomes y = 4 || -1 && 0; Hence it returns TRUE. So, y=1 Step 5: z = i && j || k; becomes z = 4 && -1 || 0; Hence it returns TRUE. So, z=1. Step 6: printf("%d, %d, %d, %d\n", w, x, y, z); Hence the output is "1, 0, 1, 1". View Answer Workspace Report Discuss in Forum

15. Assunming, integer is 2 byte, What will be the output of the program?

#include<stdio.h>
int main() { printf("%x\n", -2<<2); return 0; } A. C. ffff fff8 B. D. 0 Error

Answer & Explanation

Answer: Option C Explanation: Step 1: printf("%x\n", -2<<2); here -2 is left shifted 2 bits. Binary value of -2 is 10000000 00000010 After left shifting 2 bits 10000000 00001000 gives -8

printf("%x\n", -8); prints -8 in hexadecimal format.


Hence the output is fff8.

C Programming :: Expressions
@ : Home > C Programming > Expressions > True / False Questions

1.

The expression of the right hand side of || operators doesn't get evaluated if the left hand side determines the outcome. A. True B. False

Answer & Explanation

Answer: Option A Explanation: Because, if a is non-zero then b will not be evaluated in the expression (a || b) View Answer Workspace Report Discuss in Forum

2.

Associativity of an operator is either Left to Right or Right to Left. A. True B. False

Answer & Explanation

Answer: Option A Explanation: Yes, the associativity of an operator is either Left to Right or Right to Left. View Answer Workspace Report Discuss in Forum

3.

Associativity has no role to play unless the precedence of operator is same. A. True B. False

Answer & Explanation

Answer: Option A Explanation: Associativity is only needed when the operators in an expression have the same precedence. Usually + and - have the same precedence. Consider the expression 7 - 4 + 2. The result could be either (7 - 4) + 2 = 5or 7 - (4 + 2) = 1. The former result corresponds to the case when + and - are left-associative, the latter to when + and - are right-associative. Usually the addition, subtraction, multiplication, and division operators are left-associative, while the exponentiation, assignment and conditional operators are right-associative. To prevent cases where operands would be associated with two operators, or no operator at all, operators with the same precedence must have the same associativity.

View Answer Workspace Report Discuss in Forum

4.

In the expression a=b=5 the order of Assignment is NOT decided by Associativity of operators A. True B. Fals e

Answer & Explanation

Answer: Option B Explanation: The equal to = operator has Right-to-Left Associativity. So it assigns b=5 then a=b.

C Programming :: Expressions
@ : Home > C Programming > Expressions > Yes / No Questions

1.

Are the following two statement same? 1. a <= 20 ? b = 30: c = 30; 2. (a <=20) ? b : c = 30; No

A.

Yes

B.

Answer & Explanation

Answer: Option B Explanation: No, the expressions 1 and 2 are not same. 1. a <= 20 ? b = 30: c = 30; This statement can be rewritten as,

if(a <= 20) { b = 30; } else { c = 30; }


2. (a <=20) ? b : c = 30; This statement can be rewritten as,

if(a <= 20) { //Nothing here } else { c = 30; }


View Answer Workspace Report Discuss in Forum

2.

Will the expression *p = c be disallowed by the compiler? A. Yes B. No

Answer & Explanation

Answer: Option B Explanation: Because, here even though the value of p is accessed twice it is used to modify two different objects p and *p View Answer Workspace Report Discuss in Forum

3.

Every operator has an Associativity A. Yes B. No

Answer & Explanation

Answer: Option A Explanation: Yes, Each and every operator has an associativity. The associativity (or fixity) of an operator is a property that determines how operators of the same precedence are grouped in the absence of parentheses. Operators may be leftassociative, right-associative or non-associative. View Answer Workspace Report Discuss in Forum

4.

Two different operators would always have different Associativity. A. Yes B. No

Answer & Explanation

Answer: Option B

Explanation: No, Two different operators may have same associativity. Example: Arithmetic operators like ++ -- having Left-to-Right associativity. Relational operators like > >= also have Left-to-Right associativity.

C Programming :: Floating Point Issues


@ : Home > C Programming > Floating Point Issues > General Questions

1.

Which statement will you add in the following program to work it correctly?

#include<stdio.h>
int main() { printf("%f\n", log(36.0)); return 0; } A. C. #include<conio.h> #include<stdlib.h> B. D. #include<math.h>

#include<dos.h>

Answer & Explanation

Answer: Option B Explanation:

math.h is a header file in the standard library of C programming language designed for basic
mathematical operations. Declaration syntax: double log(double); View Answer Workspace Report Discuss in Forum

2.

We want to round off x, a float, to an int value, The correct way to do is A. C. y = (int)(x + 0.5) B. D. y = int(x + 0.5) y = (int)((int)x + 0.5)

y = (int)x + 0.5

Answer & Explanation

Answer: Option A

Explanation: Rounding off a value means replacing it by a nearest value that is approximately equal or smaller or greater to the given number.

y = (int)(x + 0.5); here x is any float value. To roundoff, we have totypecast the value of x by using (int)
Example:

#include <stdio.h> int main () { float x = 3.6; int y = (int)(x + 0.5); printf ("Result = %d\n", y ); return 0; }
Output: Result = 4. View Answer Workspace Report Discuss in Forum

3.

Which of the following statement obtains the remainder on dividing 5.5 by 1.3 ? A. C. rem = (5.5 % 1.3) rem = fmod(5.5, 1.3) B. D. rem = modf(5.5, 1.3) Error: we can't divide

Answer & Explanation

Answer: Option C Explanation:

fmod(x,y) - Calculates x modulo y, the remainder of x/y. This function is the same as the modulus operator. But fmod() performs floating point
divisions. Example:

#include <stdio.h> #include <math.h> int main () { printf ("fmod of 5.5 by 1.3 is %lf\n", fmod (5.5, 1.3) );

return 0; }
Output: fmod of 5.5 by 1.3 is 0.300000 View Answer Workspace Report Discuss in Forum

4.

Which of the following range is a valid long double ? A. C. 3.4E-4932 to 1.1E+4932 B. D. 3.4E-4932 to 3.4E+4932 1.7E-4932 to 1.7E+4932

1.1E-4932 to 1.1E+4932

Answer & Explanation

Answer: Option A Explanation: The range of long double is 3.4E-4932 to 1.1E+4932 View Answer Workspace Report Discuss in Forum

5.

What are the different types of real data type in C ? A. C. float, double float, double, long double B. D. short int, double, long int double, long int, float

Answer & Explanation

Answer: Option C Explanation: The floating point data types are called real data types. Hence float, double, andlong double are real data types.

6.

What will you do to treat the constant 3.14 as a float? A. C. use float(3.14f) use f(3.14) B. D. use 3.14f

use (f)(3.14)

Answer & Explanation

Answer: Option B

Explanation: Given 3.14 is a double constant. To specify 3.14 as float, we have to add f to the 3.14. (i.e 3.14f) View Answer Workspace Report Discuss in Forum

7.

What will you do to treat the constant 3.14 as a long double? A. C. use 3.14LD use 3.14DL B. D. use 3.14L

use 3.14LF

Answer & Explanation

Answer: Option B Explanation: Given 3.14 is a double constant. To specify 3.14 as long double, we have to add L to the 3.14. (i.e 3.14L) View Answer Workspace Report Discuss in Forum

8.

The binary equivalent of 5.375 is A. C. 101.101110111 101011 B. D. 101.011

None of above

Answer & Explanation

Answer: Option B Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

9.

A float occupies 4 bytes. If the hexadecimal equivalent of these 4 bytes are A, B, C and D, then when this float is stored in memory in which of the following order do these bytes gets stored? A. B. C. ABCD DCBA 0xABCD

D.

Depends on big endian or little endian architecture

Answer & Explanation

Answer: Option D Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

10. If the binary eauivalent of 5.375 in normalised form is 0100 0000 1010 1100 0000 0000 0000 0000, what will be the output of the program?

#include<stdio.h> #include<math.h>
int main() { float a=5.375; char *p; int i; p = (char*)&a; for(i=0; i<=3; i++) printf("%02x\n", (unsigned char)p[i]); return 0; } A. C. 40 AC 00 00 00 00 AC 40 B. D. 04 CA 00 00 00 00 CA 04

Answer & Explanation

Answer: Option C Explanation: No answer description available for this question.

C Programming :: Floating Point Issues


@ : Home > C Programming > Floating Point Issues > Find Output of Program

1.

What will be the output of the program?

#include<stdio.h>
int main()

{ float f=43.20; printf("%e, ", f); printf("%f, ", f); printf("%g", f); return 0; } A. C. 4.320000e+01, 43.200001, 43.2 B. D. 4.3, 43.22, 43.21 Error

4.3e, 43.20f, 43.00

Answer & Explanation

Answer: Option A Explanation:

printf("%e, ", f); Here '%e' specifies the "Scientific Notation" format. So, it prints the
43.20 as 4.320000e+01.

printf("%f, ", f); Here '%f' specifies the "Decimal Floating Point" format. So, it prints
the 43.20 as 43.200001.

printf("%g, ", f); Here '%g' "Use the shorter of %e or %f". So, it prints the 43.20 as
43.2. View Answer Workspace Report Discuss in Forum

2.

What will be the output of the program?

#include<stdio.h>
int main() { float d=2.25; printf("%e,", printf("%f,", printf("%g,", printf("%lf", return 0; } A. B. C. D.

d); d); d); d);

2.2, 2.50, 2.50, 2.5 2.2e, 2.25f, 2.00, 2.25 2.250000e+000, 2.250000, 2.25, 2.250000

Error

Answer & Explanation

Answer: Option C

Explanation:

printf("%e,", d); Here '%e' specifies the "Scientific Notation" format. So, it prints the
2.25 as 2.250000e+000.

printf("%f,", d); Here '%f' specifies the "Decimal Floating Point" format. So, it prints the
2.25 as 2.250000.

printf("%g,", d); Here '%g' "Use the shorter of %e or %f". So, it prints the 2.25 as 2.25. printf("%lf,", d); Here '%lf' specifies the "Long Double" format. So, it prints the 2.25 as
2.250000. View Answer Workspace Report Discuss in Forum

3.

What will be the output of the program?

#include<stdio.h>
int main() { float a=0.7; if(a < 0.7) printf("C\n"); else printf("C++\n"); return 0; } A. C. C B. D. C++ Non of above

Compiler error

Answer & Explanation

Answer: Option A Explanation:

if(a < 0.7) here a is a float variable and 0.7 is a double constant. The float variable a is less than double constant 0.7. Hence the if condition is satisfied and it prints 'C'
Example:

#include<stdio.h> int main() { float a=0.7; printf("%.10f %.10f\n",0.7, a); return 0; }

Output: 0.7000000000 0.6999999881 View Answer Workspace Report Discuss in Forum

4.

What will be the output of the program?

#include<stdio.h>
int main() { float a=0.7; if(a < 0.7f) printf("C\n"); else printf("C++\n"); return 0; } A. C. C Compiler error B. D. C++

Non of above

Answer & Explanation

Answer: Option B Explanation:

if(a < 0.7f) here a is a float variable and 0.7f is a float constant. The float variable a is not less than 0.7f float constant. But both are equal. Hence the ifcondition is failed and it goes to else it prints 'C++'
Example:

#include<stdio.h> int main() { float a=0.7; printf("%.10f %.10f\n",0.7f, a); return 0; }


Output: 0.6999999881 0.6999999881 View Answer Workspace Report Discuss in Forum

5.

What will be the output of the program?

#include<stdio.h>
int main()

{ printf("%f\n", sqrt(36.0)); return 0; } A. 6.0 6.00000 0 B. 6

C.

D.

Error: Prototype sqrt() not found.

Answer & Explanation

Answer: Option C Explanation:

printf("%f\n", sqrt(36.0)); It prints the square root of 36 in the float format(i.e


6.000000). Declaration Syntax: double sqrt(double x) calculates and return the positive square root of the given number.

6.

What will be the output of the program?

#include<stdio.h>
int main() { float fval=7.29; printf("%d\n", (int)fval); return 0; } A. C. 0 7.0 B. D. 0.0 7

Answer & Explanation

Answer: Option D Explanation:

printf("%d\n", (int)fval); It prints '7'. because, we typecast the (int)fvalin to


integer. It converts the float value to the nearest integer value. View Answer Workspace Report Discuss in Forum

7.

What will be the output of the program?

#include<stdio.h>
int main()

{ float *p; printf("%d\n", sizeof(p)); return 0; } A. B. C. D. 2 in 16bit compiler, 4 in 32bit compiler

4 in 16bit compiler, 2 in 32bit compiler 4 in 16bit compiler, 4 in 32bit compiler 2 in 16bit compiler, 2 in 32bit compiler

Answer & Explanation

Answer: Option A Explanation:

sizeof(x) returns the size of x in bytes. float *p is a pointer to a float.


In 16 bit compiler, the pointer size is always 2 bytes. In 32 bit compiler, the pointer size is always 4 bytes. View Answer Workspace Report Discuss in Forum

8.

What will be the output of the program?

#include<stdio.h> #include<math.h>
int main() { float n=1.54; printf("%f, %f\n", ceil(n), floor(n)); return 0; } 2.000000, 1.000000

A.

B.

1.500000, 1.500000

C.

1.550000, 2.000000

D.

1.000000, 2.000000

Answer & Explanation

Answer: Option A Explanation:

ceil(x) round up the given value. It finds the smallest integer not < x. floor(x) round down the given value. It finds the smallest integer not > x.

printf("%f, %f\n", ceil(n), floor(n)); In this line ceil(1.54) round up the 1.54 to 2 and floor(1.54) round down the 1.54 to 1.
In the printf("%f, %f\n", ceil(n), floor(n)); statement, the format specifier "%f %f" tells output to be float value. Hence it prints 2.000000 and 1.000000. View Answer Workspace Report Discuss in Forum

9.

What will be the output of the program?

#include<stdio.h> #include<math.h>
int main() { printf("%d, %d, %d\n", sizeof(3.14f), sizeof(3.14), sizeof(3.14l)); return 0; } A. C. 4, 4, 4 4, 8, 10 B. D. 4, 8, 8 4, 8, 12

Answer & Explanation

Answer: Option C Explanation:

sizeof(3.14f) here '3.14f' specifies the float data type. Hence size of float is 4 bytes. sizeof(3.14) here '3.14' specifies the double data type. Hence size of float is 8 bytes. sizeof(3.14l) here '3.14l' specifies the long double data type. Hence size of float is 10
bytes.

C Programming :: Functions
@ : Home > C Programming > Functions > General Questions

1.

What is the notation for following functions?

1.

int f(int a, float b) { /* Some code */ } int f(a, b)

2.

int a; float b; { /* Some code */ } 1. KR Notation 2. ANSI Notation 1. ANSI Notation 2. KR Notation 1. Pre ANSI C Notation 2. KR Notation

A.

B.

C.

D.

1. ANSI Notation 2. Pre ANSI Notation

Answer & Explanation

Answer: Option C Explanation: KR Notation means Kernighan and Ritche Notation. View Answer Workspace Report Discuss in Forum

2.

How many times the program will print "IndiaBIX" ?

#include<stdio.h>
int main() { printf("IndiaBIX"); main(); return 0; } A. C. Infinite times 65535 times B. D. 32767 times Till stack doesn't overflow

Answer & Explanation

Answer: Option D Explanation: A call stack or function stack is used for several related purposes, but the main reason for having one is to keep track of the point to which each active subroutine should return control when it finishes executing. A stack overflow occurs when too much memory is used on the call stack. Here function main() is called repeatedly and its return address is stored in the stack. After stack memory is full. It shows stack overflow error.

View Answer Workspace Report Discuss in Forum

3.

The keyword used to transfer control from a function back to the calling function is A. C. switch go back B. D. goto return

Answer & Explanation

Answer: Option D Explanation: The keyword return is used to transfer control from a function back to the calling function. Example:

#include<stdio.h> int add(int, int); /* Function prototype */ int main() { int a = 4, b = 3, c; c = add(a, b); printf("c = %d\n", c); return 0; } int add(int a, int b) { /* returns the value and control back to main() function */ return (a+b); }
Output: c=7

C Programming :: Functions
@ : Home > C Programming > Functions > Find Output of Program

1.

What will be the output of the program?

#include<stdio.h>
int sumdig(int); int main() {

int a, b; a = sumdig(123); b = sumdig(123); printf("%d, %d\n", a, b); return 0; } int sumdig(int n) { int s, d; if(n!=0) { d = n%10; n = n/10; s = d+sumdig(n); } else return 0; return s; } A. C. 4, 4 6, 6 B. D. 3, 3 12, 12

Answer & Explanation

Answer: Option C Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

2.

What will be the output of the program?

#include<stdio.h>
void fun(int*, int*); int main() { int i=5, j=2; fun(&i, &j); printf("%d, %d", i, j); return 0; } void fun(int *i, int *j) { *i = *i**i; *j = *j**j; } A. C. 5, 2 2, 5 B. D. 10, 4 25, 4

Answer & Explanation

Answer: Option D Explanation: Step 1: int i=5, j=2; Here variable i and j are declared as an integer type and initialized to 5 and 2 respectively. Step 2: fun(&i, &j); Here the function fun() is called with two parameters &iand &j (The & denotes call by reference. So the address of the variable i andj are passed. ) Step 3: void fun(int *i, int *j) This function is called by reference, so we have to use * before the parameters. Step 4: *i = *i**i; Here *i denotes the value of the variable i. We are multiplying 5*5 and storing the result 25 in same variable i. Step 5: *j = *j**j; Here *j denotes the value of the variable j. We are multiplying 2*2 and storing the result 4 in same variable j. Step 6: Then the function void fun(int *i, int *j) return back the control back to main() function. Step 7: printf("%d, %d", i, j); It prints the value of variable i and j. Hence the output is 25, 4. View Answer Workspace Report Discuss in Forum

3.

What will be the output of the program?

#include<stdio.h>
int main() { int i=1; if(!i) printf("IndiaBIX,"); else { i=0; printf("C-Program"); main(); } return 0; } A. B. C. prints "IndiaBIX, C-Program" infinitely prints "C-Program, C-Program" infinetly

prints "C-Program, IndiaBIX" infinitely

D.

Error: main() should not inside else statement

Answer & Explanation

Answer: Option B Explanation: Step 1: int i=1; The variable i is declared as an integer type and initialized to 1(one). Step 2: if(!i) Here the !(NOT) operator reverts the i value 1 to 0. Hence theif(0) condition fails. So it goes to else part. Step 3: else { i=0; In the else part variable i is assigned to value 0(zero). Step 4: printf("C-Program"); It prints the "C-program". Step 5: main(); Here we are calling the main() function. After calling the function, the program repeats from step 1 to step 5 infinitely. Hence it prints "C-Program, C-Program" infinetly View Answer Workspace Report Discuss in Forum

4.

What will be the output of the program?

#include<stdio.h>
int main() { void fun(char*); char a[100]; a[0] = 'A'; a[1] = 'B'; a[2] = 'C'; a[3] = 'D'; fun(&a[0]); return 0; } void fun(char *a) { a++; printf("%c", *a); a++; printf("%c", *a); } A. C. AB CD B. D. BC

No output

Answer & Explanation

Answer: Option B

Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

5.

What will be the output of the program?

#include<stdio.h>
int main() { int fun(); int i; i = fun(); printf("%d\n", i); return 0; } int fun() { _AX = 1990; } A. C. Garbage value 1990 B. D. 0 No output

Answer & Explanation

Answer: Option C Explanation: The return value of the function is taken from the Accumulator _AX=1990.

6.

What will be the output of the program?

#include<stdio.h>
int main() { int fun(int); int i = fun(10); printf("%d\n", --i); return 0; } int fun(int i) { return (i++); } A. 9 B. 10

C.

11

D.

Answer & Explanation

Answer: Option A Explanation: Step 1: int fun(int); Here we declare the prototype of the function fun(). Step 2: int i = fun(10); The variable i is declared as an integer type and the result of the fun(10) will be stored in the variable i. Step 3: int fun(int i){ return (i++); } Inside the fun() we are returning a value return(i++). It returns 10. because i++ is the post-increement operator. Step 4: Then the control back to the main function and the value 10 is assigned to variable i. Step 5: printf("%d\n", --i); Here --i denoted pre-increement. Hence it prints the value 9. View Answer Workspace Report Discuss in Forum

7.

What will be the output of the program?

#include<stdio.h>
int fun(int, int); typedef int (*pf) (int, int); int proc(pf, int, int); int main() { printf("%d\n", return 0; } int fun(int a, int { return (a==b); } int proc(pf p, int { return ((*p)(a, } A. C. 6 0

proc(fun, 6, 6)); b)

a, int b) b));

B. D.

-1

Answer & Explanation

Answer: Option B Explanation:

No answer description available for this question. View Answer Workspace Report Discuss in Forum

8.

What will be the output of the program?

#include<stdio.h>
int fun(int, int); typedef int (*pf) (int, int); int proc(pf, int, int); int main() { int a=3; fun(a); return 0; } void fun(int n) { if(n > 0) { fun(--n); printf("%d,", n); fun(--n); } } A. C. 0, 2, 1, 0 0, 1, 0, 2 B. D. 1, 1, 2, 0 0, 1, 2, 0

Answer & Explanation

Answer: Option D Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

9.

What will be the output of the program?

#include<stdio.h>
int func1(int); int main() { int k=35; k = func1(k=func1(k=func1(k))); printf("k=%d\n", k); return 0; } int func1(int k) {

k++; return k; } A. C. k=35 k=37 B. D. k=36 k=38

Answer & Explanation

Answer: Option D Explanation: Step 1: int k=35; The variable k is declared as an integer type and initialized to 35. Step 2: k = func1(k=func1(k=func1(k))); The func1(k) increement the value of k by 1 and return it. Here the func1(k) is called 3 times. Hence it increements value of k = 35 to 38. The result is stored in the variable k = 38. Step 3: printf("k=%d\n", k); It prints the value of variable k "38". View Answer Workspace Report Discuss in Forum

10. If int is 2 bytes wide.What will be the output of the program?

#include<stdio.h>
void fun(char**); int main() { char *argv[] = {"ab", "cd", "ef", "gh"}; fun(argv); return 0; } void fun(char **p) { char *t; t = (p+= sizeof(int))[-1]; printf("%s\n", t); } c d

A.

ab

B.

C.

ef

D.

gh

Answer & Explanation

Answer: Option B Explanation: No answer description available for this question.

C Programming :: Functions
@ : Home > C Programming > Functions > Find Output of Program

11. What will be the output of the program?

#include<stdio.h>
int main() { int fun(int); int i=3; fun(i=fun(fun(i))); printf("%d\n", i); return 0; } fun(int i) { i++; return i; } A. C. 5 B. D. 4 Garbage value

Error

Answer & Explanation

Answer: Option A Explanation: Step 1: int fun(int); This is prototype of function fun(). It tells the compiler that the function fun() accept one integer parameter and returns an integer value. Step 2: int i=3; The variable i is declared as an integer type and initialized to value 3. Step 3: fun(i=fun(fun(i)));. The function fun(i) increements the value of i by 1(one) and return it. Lets go step by step, => fun(i) becomes fun(3) is called and it returns 4. => i = fun(fun(i)) becomes i = fun(4) is called and it returns 5 and stored in variable i.(i=5) => fun(i=fun(fun(i))); becomes fun(5); is called and it return 6 and nowhere the

return value is stored. Step 4: printf("%d\n", i); It prints the value of variable i.(5) Hence the output is '5'. View Answer Workspace Report Discuss in Forum

12. What will be the output of the program?

#include<stdio.h>
int fun(int); int main() { float k=3; fun(k=fun(fun(k))); printf("%f\n", k); return 0; } int fun(int i) { i++; return i; } 5.00000 0

A.

B.

3.000000

C.

Garbage value

D.

4.000000

Answer & Explanation

Answer: Option A Explanation: Step 1: int fun(int); This is prototype of function fun(). It tells the compiler that the function fun() accept one integer parameter and returns an integer value. Step 2: float k=3; The variable k is declared as an float type and initialized to value 3. Step 3: fun(k=fun(fun(k)));. The function fun(k) increements the value of k by 1(one) and return it. Lets go step by step, => fun(k) becomes fun(3) is called and it returns 4. => i = fun(fun(k)) becomes i = fun(4) is called and it returns 5 and stored in variable k.(i=5) => fun(i=fun(fun(k))); becomes fun(5); is called and it return 6 and nowhere the

return value is stored. Step 4: printf("%f\n", i); It prints the value of variable i(5.000000) Hence the output is '5.000000'. View Answer Workspace Report Discuss in Forum

13. What will be the output of the program?

#include<stdio.h>
int i; int fun1(int); int fun2(int); int main() { extern int j; int i=3; fun1(i); printf("%d,", i); fun2(i); printf("%d", i); return 0; } int fun1(int j) { printf("%d,", ++j); return 0; } int fun2(int i) { printf("%d,", ++i); return 0; } int j=1; A. C. 3, 4, 4, 3 3, 3, 4, 4 B. D. 4, 3, 4, 3

3, 4, 3, 4

Answer & Explanation

Answer: Option B Explanation: Step 1: int i; The variable i is declared as an global and integer type. Step 2: int fun1(int); This prototype tells the compiler that the fun1() accepts the one integer parameter and returns the integer value. Step 3: int fun2(int); This prototype tells the compiler that the fun2() accepts the one integer parameter and returns the integer value. Step 4: extern int j; Inside the main function, the extern variable j is declared and

defined in another source file. Step 5: int i=3; The local variable i is defines as an integer type and initialized to 3. Step 6: fun1(i); The fun1(i) increements the given value of variable i prints it. Here fun1(i) becomes fun1(3) hence it prints '4' then the control is given back to the main function. Step 7: printf("%d,", i); It prints the value of local variable i. So, it prints '3'. Step 8: fun2(i); The fun2(i) increements the given value of variable i prints it. Here fun2(i) becomes fun2(3) hence it prints '4' then the control is given back to the main function. Step 9: printf("%d,", i); It prints the value of local variable i. So, it prints '3'. Hence the output is "4 3 4 3". View Answer Workspace Report Discuss in Forum

15. What will be the output of the program?

#include<stdio.h>
int i; int fun(); int main() { while(i) { fun(); main(); } printf("Hello\n"); return 0; } int fun() { printf("Hi"); } A. C. Hello B. D. Hi Hello Infinite loop

No output

Answer & Explanation

Answer: Option A Explanation: Step 1: int i; The variable i is declared as an integer type. Step 1: int fun(); This prototype tells the compiler that the function fun() does not accept any arguments and it returns an integer value. Step 1: while(i) The value of i is not initialized so this while condition is failed. So, it does not execute the while block. Step 1: printf("Hello\n"); It prints "Hello". Hence the output of the program is "Hello".

16. What will be the output of the program?

#include<stdio.h> #include<stdlib.h>
int main() { int i=0; i++; if(i<=5)

{ printf("IndiaBIX"); exit(1); main(); } return 0; } A. B. C. Prints "IndiaBIX" 5 times Function main() doesn't calls itself Infinite loop Prints "IndiaBIx"

D.

Answer & Explanation

Answer: Option D Explanation: Step 1: int i=0; The variable i is declared as in integer type and initialized to '0'(zero). Step 2: i++; Here variable i is increemented by 1. Hence i becomes '1'(one). Step 3: if(i<=5) becomes if(1 <=5). Hence the if condition is satisfied and it enter into if block statements. Step 4: printf("IndiaBIX"); It prints "IndiaBIX". Step 5: exit(1); This exit statement terminates the program execution. Hence the output is "IndiaBIx". View Answer Workspace Report Discuss in Forum

17. What will be the output of the program?

#include<stdio.h>
int main() { int i=3, j=4, k, l; k = addmult(i, j); l = addmult(i, j); printf("%d, %d\n", k, l); return 0; } int addmult(int ii, int jj) { int kk, ll; kk = ii + jj;

ll = ii * jj; return (kk, ll); } A. C. 12, 12 B. D. 7, 7 12, 7

7, 12

Answer & Explanation

Answer: Option A Explanation: Step 1: int i=3, j=4, k, l; The variables i, j, k, l are declared as an integer type and variable i, j are initialized to 3, 4 respectively. The function addmult(i, j); accept 2 integer parameters. Step 2: k = addmult(i, j); becomes k = addmult(3, 4) In the function addmult(). The variable kk, ll are declared as an integer typeint kk,

ll; kk = ii + jj; becomes kk = 3 + 4 Now the kk value is '7'. ll = ii * jj; becomes ll = 3 * 4 Now the ll value is '12'. return (kk, ll); It returns the value of variable ll only.
The value 12 is stored in variable 'k'. Step 3: l = addmult(i, j); becomes l = addmult(3, 4)

kk = ii + jj; becomes kk = 3 + 4 Now the kk value is '7'. ll = ii * jj; becomes ll = 3 * 4 Now the ll value is '12'. return (kk, ll); It returns the value of variable ll only.
The value 12 is stored in variable 'l'. Step 4: printf("%d, %d\n", k, l); It prints the value of k and l Hence the output is "12, 12". View Answer Workspace Report Discuss in Forum

18. What will be the output of the program?

#include<stdio.h>
int check(int); int main() { int i=45, c; c = check(i); printf("%d\n", c); return 0; } int check(int ch) { if(ch >= 45) return 100; else return 10; } A. C. 100 B. D. 10 0

Answer & Explanation

Answer: Option A Explanation: Step 1: int check(int); This prototype tells the compiler that the functioncheck() accepts one integer parameter and returns an integer value. Step 2: int l=45, c; The variable i and c are declared as an integer type and iis initialized to 45. The function check(i) return 100 if the given value of variable i is >=(greater than or equal to) 45, else it will return 10. Step 3: c = check(i); becomes c = check(45); The function check() return 100 and it get stored in the variable c.(c = 100) Step 4: printf("%d\n", c); It prints the value of variable c. Hence the output of the program is '100'. View Answer Workspace Report Discuss in Forum

19. What will be the output of the program?

#include<stdio.h>
int main() { int i=3, j=4, k, l; k = addmult(i, j); l = addmult(i, j); printf("%d %d\n", k, l);

return 0; } int addmult(int ii, int jj); { int kk, ll; kk = ii + jj; ll = ii * jj; return (kk, ll); } A. B. C. D. Function addmult()return 7 and 12 No output Error: Compile error

None of above

Answer & Explanation

Answer: Option C Explanation: There is an error in this statement int addmult(int ii, int jj);. We have to remove the semi-colon, because it was an definition of the function addmult() View Answer Workspace Report Discuss in Forum

20. What will be the output of the program?

#include<stdio.h>
int check (int, int); int main() { int c; c = check(10, 20); printf("c=%d\n", c); return 0; } int check(int i, int j) { int *p, *q; p=&i; q=&j; i>=45 ? return(*p): return(*q); } A. C. Print 10 Print 1 B. D. Print 20 Compile error

Answer & Explanation

Answer: Option D Explanation: There is an error in this line i>=45 ? return(*p): return(*q);. We cannot usereturn keyword in the terenary operators.

21. What will be the output of the program?

#include<stdio.h>
int reverse(int); int main() { int no=5; reverse(no); return 0; } int reverse(int no) { if(no == 0) return 0; else printf("%d,", no); reverse (no--); } A. C. Print 5, 4, 3, 2, 1 Print 5, 4, 3, 2, 1, 0 B. D. Print 1, 2, 3, 4, 5 Infinite loop

Answer & Explanation

Answer: Option D Explanation: Step 1: int no=5; The variable no is declared as integer type and initialized to 5. Step 2: reverse(no); becomes reverse(5); It calls the function reverse() with '5' as parameter. The function reverse accept an integer number 5 and it returns '0'(zero) if(5 == 0) if the given number is '0'(zero) or else printf("%d,", no); it prints that number 5 and calls the function reverse(5);. The function runs infinetely because the there is a post-increement operator is used. So, it calls reverse(5) infinetely. loops

C Programming :: Functions
@ : Home > C Programming > Functions > Point Out Errors

1.

Point out the error in the program

f(int a, int b) { int a; a = 20; return a; } A. B. C. D. Missing parenthesis in return statement The function should be defined as int f(int a, int b) Redeclaration of a

None of above

Answer & Explanation

Answer: Option C Explanation:

f(int a, int b) The variable a is declared in the function argument statement. int a; Here again we are declaring the variable a. Hence it shows the error "Redeclaration of
a" View Answer Workspace Report Discuss in Forum

2.

Point out the error in the program

#include<stdio.h>
int main() { int a=10; void f(); a = f(); printf("%d\n", a); return 0; } void f() { printf("Hi"); } A. B. Error: Prototype declaration

Error: Doesn't print anything

C. D.

No error None of above

Answer & Explanation

Answer: Option A Explanation: The function void f() is not visible to the compiler. So we have to declare this prototype void f(); after the include statement. View Answer Workspace Report Discuss in Forum

3.

Point out the error in the program

#include<stdio.h>
int main() { int f(int); int b; b = f(20); printf("%d\n", b); return 0; } int f(int a) { a > 20? return(10): return(20); } A. B. C. D. Error: Prototype declaration No error Error: return statement cannot be used with conditional operators

None of above

Answer & Explanation

Answer: Option C Explanation: In a ternary operator, we cannot use the return statement. The ternary operator requires expressions but not code.

C Programming :: Functions

@ : Home > C Programming > Functions > Point Out Correct Statements

1.

There is a error in the below program. Which statement will you add to remove it?

#include<stdio.h>
int main() { int a; a = f(10, 3.14); printf("%d\n", a); return 0; } float f(int aa, float bb) { return ((float)aa + bb); } A. B. C. D. Add prototype: float f(aa, bb) Add prototype: float f(int, float)

Add prototype: float f(float, int) Add prototype: float f(bb, aa)

Answer & Explanation

Answer: Option B Explanation: This program will create an error "Type mismatch in redeclaration of f". To overcome this error, we have to add function prototype of f. The correct form of function f prototype is float f(int, float); View Answer Workspace Report Discuss in Forum

2.

Which of the following statements are correct about the program?

#include<stdio.h>
int main() { printf("%p\n", main()); return 0; }

A. B. C. D.

It prints garbage values infinitely Runs infinitely without printing anything

Error: main() cannot be called inside printf() No Error and print nothing

Answer & Explanation

Answer: Option B Explanation: In printf("%p\n", main()); it calls the main() function and then it repeats infinetly, untill stack overflow. View Answer Workspace Report Discuss in Forum

3.

Which of the following statements are correct about the program?

#include<stdio.h>
long fun(int num) { int i; long f=1; for(i=1; i<=num; i++) f = f * i; return f; } A. B. C. D. The function calculates the value of 1 raised to power num. The function calculates the square root of an integer The function calculates the factorial value of an integer

None of above

Answer & Explanation

Answer: Option C Explanation: Yes, this function calculates and return the factorial value of an given integer num.

C Programming :: Functions

@ : Home > C Programming > Functions > True / False Questions

1.

In C all functions except main() can be called recursively. A. True B. Fals e

Answer & Explanation

Answer: Option B Explanation: Any function including main() can be called recursively. View Answer Workspace Report Discuss in Forum

2.

A function cannot be defined inside another function A. True B. False

Answer & Explanation

Answer: Option A Explanation: True, A function cannot be defined inside the another function. but a function can be called inside a another function. View Answer Workspace Report Discuss in Forum

3.

Functions can be called either by value or reference A. True B. False

Answer & Explanation

Answer: Option A Explanation: True, A function can be called either call by value or call by reference. Example: Call by value means c = sub(a, b); here value of a and b are passed.

Call by reference means c = sub(&a, &b); here address of a and b are passed. View Answer Workspace Report Discuss in Forum

4.

Functions cannot return more than one value at a time A. True B. False

Answer & Explanation

Answer: Option A Explanation: True, A function cannot return more than one value at a time. because after returning a value the control is given back to calling function. View Answer Workspace Report Discuss in Forum

5.

Names of functions in two different files linked together must be unique A. True B. False

Answer & Explanation

Answer: Option A Explanation: True, If two function are declared in a same name, it gives "Error: Multiple declaration of function_name())".

6.

A function may have any number of return statements each returning different values. A. True B. False

Answer & Explanation

Answer: Option A Explanation: True, A function may have any number of return statements each returning different values and each return statements will not occur successively. View Answer Workspace Report Discuss in Forum

7.

If return type for a function is not specified, it defaults to int A. True B. False

Answer & Explanation

Answer: Option A Explanation: True, The default return type for a function is int.

C Programming :: Functions
@ : Home > C Programming > Functions > Yes / No Questions

1.

Every function must return a value A. Yes B. No

Answer & Explanation

Answer: Option B Explanation: No, If a function return type is declared as void it cannot return any value. View Answer Workspace Report Discuss in Forum

2.

Maximum number of arguments that a function can take is 12 A. Yes B. No

Answer & Explanation

Answer: Option B Explanation: No, C can accept upto 127 maximum number of arguments in a function. View Answer Workspace Report Discuss in Forum

3.

Functions cannot return a floating point number A. Yes B. No

Answer & Explanation

Answer: Option B

Explanation: A function can return floating point value. Example:

#include <stdio.h> float sub(float, float); /* Function prototype */ int main() { float a = 4.5, b = 3.2, c; c = sub(a, b); printf("c = %f\n", c); return 0; } float sub(float a, float b) { return (a - b); }
Output: c = 1.300000 View Answer Workspace Report Discuss in Forum

4.

Will the following functions work?

int f1(int { return } int f2(int { return } A. Yes

a, int b) ( f2(20) ); a) (a*a);

B.

No

Answer & Explanation

Answer: Option A Explanation: Yes, It will return the value 20*20 = 400 Example:

#include <stdio.h> int f1(int, int); /* Function prototype */ int f2(int); /* Function prototype */ int main() { int a = 2, b = 3, c; c = f1(a, b); printf("c = %d\n", c); return 0; } int f1(int a, int b) { return ( f2(20) ); } int f2(int a) { return (a * a); }
Output: c = 400 View Answer Workspace Report Discuss in Forum

5.

In a function two return statements should never occur. A. Yes B. No

Answer & Explanation

Answer: Option B Explanation: No, In a function two return statements can occur but not successively. Example:

#include <stdio.h> int mul(int, int); /* Function prototype */ int main() { int a = 0, b = 3, c; c = mul(a, b); printf("c = %d\n", c); return 0; }

/* Two return statements in the mul() function */ int mul(int a, int b) { if(a == 0 || b == 0) { return 0; } else { return (a * b); } }
Output: c=0

6.

In a function two return statements should never occur successively. A. Yes B. No

Answer & Explanation

Answer: Option A Explanation: Yes, In a function two return statements should never occur successively. This will create a "Warning: Unreachable code" Example:

#include<stdio.h> int mul(int, int); /* Function prototype */ int main() { int a = 4, b = 3, c; c = add(a, b); printf("c = %d\n", c); return 0; } int mul(int a, int b) { return (a * b); return (a - b); /* Warning: Unreachable code */ }
Output: c = 12 View Answer Workspace Report Discuss in Forum

7.

Usually recursion works slower than loops. A. Yes B. No

Answer & Explanation

Answer: Option A Explanation: When a recursive call is made, the function/process clones itself and then process that funtion. This leads to time and space constrains. In a loop, there is no recursive call involved that saves a lot of time and space too. View Answer Workspace Report Discuss in Forum

8.

Is it true that too many recursive calls may result into stack overflow? A. Yes B. No

Answer & Explanation

Answer: Option A Explanation: Yes, too many recursive calls may result into stack overflow. because when a function is called its return address is stored in stack. After sometime the stack memory will be filled completely. Hence stack overflowerror will occur.

C Programming :: Bitwise Operators


@ : Home > C Programming > Bitwise Operators > General Questions

1.

In which numbering system can the binary number 1011011111000101 be easily converted to? A. C. Decimal system Octal system B. D. Hexadecimal system

No need to convert

Answer & Explanation

Answer: Option B Explanation: Hexadecimal system is better, because each 4-digit binary represents one Hexadecimal digit.

View Answer Workspace Report Discuss in Forum

2.

Which bitwise operator is suitable for checking whether a particular bit is on or off? A. C. && operator || operator B. D. & operator

! operator

Answer & Explanation

Answer: Option B Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

3.

Which bitwise operator is suitable for turning off a particular bit in a number? A. C. && operator || operator B. D. & operator

! operator

Answer & Explanation

Answer: Option B Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

4.

Which bitwise operator is suitable for turning on a particular bit in a number? A. C. && operator || operator B. D. & operator | operator

Answer & Explanation

Answer: Option D Explanation: No answer description available for this question.

C Programming :: Bitwise Operators


@ : Home > C Programming > Bitwise Operators > Find Output of Program

1.

What will be the output of the program ?

#include<stdio.h>
int main() { int i=32, j=0x20, k, l, m; k=i|j; l=i&j; m=k^l; printf("%d, %d, %d, %d, %d\n", i, j, k, l, m); return 0; } A. 0, 0, 0, 0, 0 32, 32, 32, 32, 0 B. 0, 32, 32, 32, 32

C.

D.

32, 32, 32, 32, 32

Answer & Explanation

Answer: Option C Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

2.

What will be the output of the program ?

#include<stdio.h>
int main() { int i=4, j=8; printf("%d, %d, %d\n", i|j&j|i, i|j&&j|i, i^j); return 0; } A. 4, 8, 0 12, 1, 12 B. 1, 2, 1

C.

D.

0, 0, 0

Answer & Explanation

Answer: Option C Explanation:

No answer description available for this question. View Answer Workspace Report Discuss in Forum

3.

If an unsigned int is 2 bytes wide then, What will be the output of the program ?

#include<stdio.h>
int main() { unsigned int m = 32; printf("%x\n", ~m); return 0; } A. ffff ffd f B. 0000

C.

D.

ddfd

Answer & Explanation

Answer: Option C Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

4.

If an unsigned int is 2 bytes wide then, What will be the output of the program ?

#include<stdio.h>
int main() { unsigned int a=0xffff; ~a; printf("%x\n", a); return 0; } A. C. ffff B. D. 0000 ddfd

00ff

Answer & Explanation

Answer: Option A Explanation:

No answer description available for this question. View Answer Workspace Report Discuss in Forum

5.

What will be the output of the program?

#include<stdio.h>
int main() { printf("%d >> %d %d >> %d\n"4 >> 1, 8 >> 1); return 0; } A. B. 4181 4 >> 1 8 >> 1 2 >> 4 Garbage value >> Garbage value

C.

D.

24

Answer & Explanation

Answer: Option C Explanation: No answer description available for this question.

6.

Assuming a integer 2-bytes, What will be the output of the program?

#include<stdio.h>
int main() { printf("%x\n", -1<<3); return 0; } A. C. ffff 0 B. D. fff8

-1

Answer & Explanation

Answer: Option B Explanation:

No answer description available for this question. View Answer Workspace Report Discuss in Forum

7.

What will be the output of the program?

#include<stdio.h>
int main() { unsigned int res; res = (64 >>(2+1-2)) & (~(1<<2)); printf("%d\n", res); return 0; } A. C. 32 B. D. 64 128

Answer & Explanation

Answer: Option A Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

8.

What will be the output of the program?

#include<stdio.h>
int main() { printf("%d printf("%d printf("%d printf("%d return 0; }

%d\n", %d\n", %d\n", %d\n",

32<<1, 32<<0); 32<<-1, 32<<-0); 32>>1, 32>>0); 32>>-1, 32>>-0);

A.

Garbage values

B.

64 32 0 32 16 32 0 32

C.

All zeros

D.

80 00 32 0 0 16

Answer & Explanation

Answer: Option B Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

9.

What will be the output of the program?

#include<stdio.h>
int main() { unsigned char i = 0x80; printf("%d\n", i<<1); return 0; } A. C. 0 100 B. D. 256

80

Answer & Explanation

Answer: Option B Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

10. What will be the output of the program?

#define P printf("%d\n", -1^~0); #define M(P) int main()


{ P; return 0; } M(P); A. C. 1 B. D. 0 2

-1

Answer & Explanation

Answer: Option A Explanation: No answer description available for this question.

11. Assunming, integer is 2 byte, What will be the output of the program?

#include<stdio.h>
int main() { printf("%x\n", -1>>1); return 0; } A. C. ffff B. D. 0fff fff0

0000

Answer & Explanation

Answer: Option A Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

12. What will be the output of the program?

#include<stdio.h>
int main() { char c=48; int i, mask=01; for(i=1; i<=5; i++) { printf("%c", c|mask); mask = mask<<1; } return 0; } A. C. 12400 12500 B. D. 12480

12556

Answer & Explanation

Answer: Option B Explanation: No answer description available for this question.

C Programming :: Bitwise Operators


@ : Home > C Programming > Bitwise Operators > Point Out Correct Statements

1.

Which of the following statements are correct about the program?

#include<stdio.h>
int main() { unsigned int m[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; unsigned char n, i; scanf("%d", &n); for(i=0; i<=7; i++) { if(n & m[i]) printf("yes"); } return 0; } A. B. C. D. It will put OFF all bits that are ON in the number n It will test whether the individual bits of n are ON or OFF

It will put ON all bits that are OFF in the number n It will report compilation errors in the if statement.

Answer & Explanation

Answer: Option B Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

2.

Which of the following statements are correct about the program?

#include<stdio.h>
char *fun(unsigned int num, int base); int main() { char *s; s=fun(128, 2); s=fun(128, 16); printf("%s\n"s); return 0; } char *fun(unsigned int num, int base) { static char buff[33]; char *ptr = &buff[sizeof(buff)-1]; *ptr = '\0'; do { *-ptr = "0123456789abcdef"[num %base] num /=base; }while(num!=0); return ptr; } A. B. C. D. It converts a number to a given base.

It converts a number to its equivalent binary. It converts a number to its equivalent hexadecimal. It converts a number to its equivalent octal.

Answer & Explanation

Answer: Option A Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

3.

Which of the following statements are correct about the program?

#include<stdio.h>
int main() { unsigned int num; int c=0; scanf("%u", &num); for(;num;num>=1) { if(num & 1) c++; } printf("%d", c);

return 0; } A. B. C. D. It counts the number of bits that are on in the number num.

It sets all bits in the number num to 1 It sets all bits in the number num to 0 Error

Answer & Explanation

Answer: Option A Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

4.

Which of the following statements are correct about the program?

#include<stdio.h>
int main() { unsigned int num; int i; scanf("%u", &num); for(i=0; i&lt16; i++) { printf("%d", (num<<i & 1<<15)?1:0); } return 0; } A. B. C. D. It prints all even bits from num It prints all odd bits from num It prints binary equivalent num

Error

Answer & Explanation

Answer: Option C Explanation: No answer description available for this question.

C Programming :: Bitwise Operators


@ : Home > C Programming > Bitwise Operators > True / False Questions

1.

On left shifting, the bits from the left are rotated and brought to the right and accommodated where there is empty space on the right? A. True B. Fals e

Answer & Explanation

Answer: Option B Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

2.

Left shifting a number by 1 is always equivalent to multiplying it by 2. A. True B. False

Answer & Explanation

Answer: Option A Explanation: 0001 0010 0100 1000 => => => => 1 2 4 8

View Answer Workspace Report Discuss in Forum

3.

Left shifting an unsigned int or char by 1 is always equivalent to multiplying it by 2. A. True B. False

Answer & Explanation

Answer: Option A Explanation: No answer description available for this question.

View Answer Workspace Report Discuss in Forum

4.

In the statement expression1 >> expression2. if expression1 is a signed integer with its leftmost bit set to 1 then on right shifting it the result of the statement will vary from computer to computer A. True B. False

Answer & Explanation

Answer: Option A Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

5.

Bitwise & and | are unary operators A. True B. Fals e

Answer & Explanation

Answer: Option B Explanation: Bitwise & and | are not unary operators only bitwise ! is unary operator.

6.

Bitwise & can be used to check if a bit in number is set or not. A. True B. False

Answer & Explanation

Answer: Option A Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

7.

Bitwise & can be used to check if more than one bit in a number is on. A. True B. False

Answer & Explanation

Answer: Option A

Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

8.

Bitwise & can be used to divide a number by powers of 2 A. True B. Fals e

Answer & Explanation

Answer: Option B Explanation: No answer description available for this question.

C Programming :: Bitwise Operators


@ : Home > C Programming > Bitwise Operators > Yes / No Questions

1.

Bitwise & can be used in conjunction with ~ operator to turn off 1 or more bits in a number. A. Yes B. No

Answer & Explanation

Answer: Option A Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

2.

Bitwise | can be used to set a bit in number. A. Yes B. No

Answer & Explanation

Answer: Option A Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

3.

Bitwise | can be used to set multiple bits in number. A. Yes B. No

Answer & Explanation

Answer: Option A Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

4.

Bitwise | can be used to multiply a number by powers of 2. A. Yes B. No

Answer & Explanation

Answer: Option B Explanation: No answer description available for this question. View Answer Workspace Report Discuss in Forum

5.

Bitwise can be used to perform addition and subtraction. A. Yes B. No

Answer & Explanation

Answer: Option B Explanation: No answer description available for this question.

6.

Bitwise can be used to generate a random number. A. Yes B. No

Answer & Explanation

Answer: Option B Explanation: No answer description available for this question.

View Answer Workspace Report Discuss in Forum

7.

Bitwise can be used to reverse a sign of a number. A. Yes B. No

Answer & Explanation

Answer: Option B Explanation: No answer description available for this question.

C Programming :: Arrays
@ : Home > C Programming > Arrays > General Questions

1.

In C, if you pass an array as an argument to a function, what actually gets passed? A. B. Value of elements in array First element of the array Base address of the array

C.

D.

Address of the last element of array

Answer & Explanation

Answer: Option C Explanation: The statement 'C' is correct. When we pass an array as a funtion argument, the base address of the array will be passed. View Answer Workspace Report Discuss in Forum

2.

What does the following declaration mean?

int (*ptr)[10]
A.

ptr is array of pointers to 10 integers ptr is a pointer to an array of 10

B.

integers

C. D.

ptr is an array of 10 integers ptr is an pointer to array

Answer & Explanation

Answer: Option B Explanation: The statement 'B' is correct. ptr is a pointer to an array of 10 integers View Answer Workspace Report Discuss in Forum

3.

What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array? A. B. The element will be set to 0. The compiler would report an error. The program may crash if some important data gets overwritten.

C.

D.

The array size would appropriately grow.

Answer & Explanation

Answer: Option C Explanation: If the index of the array size is exceeded, the program will crash. Hence "option c" is the correct answer. Example: Run the below program, it will crash

#include<stdio.h> int main() { int arr[2]; arr[3]=10; printf("%d",arr[3]); return 0; }

C Programming :: Arrays
@ : Home > C Programming > Arrays > Find Output of Program

1.

What will be the output of the program ?

#include<stdio.h>
int main() { int arr[5], i=0; while(i<5) arr[i]=++i; for(i=0; i<6; i++) printf("%d, ", arr[i]); return 0; } Garbage value, 1, 2, 3, 4, 5

A.

1, 2, 3, 4, 5

B.

C.

0, 1, 2, 3, 4

D.

2, 3, 4, 5, 6

Answer & Explanation

Answer: Option B Explanation: Step 1: int arr[5], i=0; The variable arr[5] is declared as an integer array with size of 5. The variable i is declared as an integer type and initialized to '0'(zero). Step 2: while(i<5) This loop will run untill the value of i is greater than 5 Loop 1: while(0 > 5){ arr[i]=++i; } becomes arr[1]=1; Loop 2: while(1 > 5){ arr[i]=++i; } becomes arr[2]=2; Loop 3: while(2 > 5){ arr[i]=++i; } becomes arr[3]=3; Loop 4: while(3 > 5){ arr[i]=++i; } becomes arr[4]=4; Loop 5: while(4 > 5){ arr[i]=++i; } becomes arr[5]=5; Loop 6: while(5 > 5) here the while condition is failed. Hence it breaks the loop. Note that in the above while loop the arr[0] is never get initialized. Step 3: for(i=0; i<6; i++) { printf("%d, ", arr[i]); }This line prints all the value of arr Hence the output of the program is "Garbage value, 1, 2, 3, 4, 5" View Answer Workspace Report Discuss in Forum

2.

What will be the output of the program ?

#include<stdio.h>
int main() { int arr[5], i=-1, z; while(i<5) arr[i]=++i; for(i=0; i<6; i++) printf("%d, ", arr[i]); return 0; } A. 1, 2, 3, 4, 5 0, 1, 2, 3, 4, 5 B. -1, 0, 1, 2, 3, 4

C.

D.

0, -1, -2, -3, -4

Answer & Explanation

Answer: Option C Explanation: Step 1: int arr[5], i=-1; The variable arr[5] is declared as an integer array with size of 5. The variable i is declared as an integer type and initialized to '-1'. Step 2: while(i<5) This loop will run untill the value of i is greater than 5 Loop 1: while(-1 > 5){ arr[i]=++i; } becomes arr[0]=0; Loop 2: while(0 > 5){ arr[i]=++i; } becomes arr[1]=1; Loop 3: while(1 > 5){ arr[i]=++i; } becomes arr[2]=2; Loop 4: while(2 > 5){ arr[i]=++i; } becomes arr[3]=3; Loop 5: while(3 > 5){ arr[i]=++i; } becomes arr[4]=4; Loop 6: while(4 > 5){ arr[i]=++i; } becomes arr[5]=5; Loop 7: while(5 > 5) here the while condition is failed. Hence it breaks the loop. Step 3: for(i=0; i<6; i++) { printf("%d, ", arr[i]); }This line prints all the value of arr Hence the output of the program is "0, 1, 2, 3, 4, 5" View Answer Workspace Report Discuss in Forum

3.

What will be the output of the program ?

#include<stdio.h>
int main() { int arr[1]={10}; printf("%d\n", 0[arr]); return 0; } A. C. 1 0 B. D. 10

Answer & Explanation

Answer: Option B Explanation: Step 1: int arr[1]={10}; The variable arr[1] is declared as an integer array with size '2' and it's first element is initialized to value '10'(means arr[0]=10) Step 2: printf("%d\n", 0[arr]); It prints the first element value of the variablearr. Hence the output of the program is 10. View Answer Workspace Report Discuss in Forum

4.

What will be the output of the program if the array begins 1200 in memory?

#include<stdio.h>
int main() { int arr[]={2, 3, 4, 1, 6}; printf("%u, %u, %u\n", arr, &arr[0], &arr); return 0; } 1200, 1200, 1200

A.

1200, 1202, 1204

B.

C.

1200, 1204, 1208

D.

1200, 1202, 1200

Answer & Explanation

Answer: Option B Explanation: Step 1: int arr[]={2, 3, 4, 1, 6}; The variable arr is declared as an integer array

and initialized. Step 2: printf("%u, %u, %u\n", arr, &arr[0], &arr); Here, The base address of the array is 1200. => arr, &arr is pointing to the base address of the array arr. => &arr[0] is pointing to the address of the first element array arr. (ie. base address) Hence the output of the program is 1200, 1200, 1200 View Answer Workspace Report Discuss in Forum

5.

What will be the output of the program ?

#include<stdio.h>
int main() { static int arr[] = {0, 1, 2, 3, 4}; int *p[] = {arr, arr+1, arr+2, arr+3, arr+4}; int **ptr=p; ptr++; printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr); *ptr++; printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr); *++ptr; printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr); ++*ptr; printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr); return 0; } 0, 1, 2, 3, 1, 1 2, 2 3, 3 3, 4 0, 1, 2, 3, 0 1 2 3 1, 2, 3, 4, 1, 2, 3, 4, 2 3 4 1

A.

B.

1, 2, 3, 4, D. 0, 1, 2, 3, 1, 2, 3, 4, 2 3 4 5

C.

Answer & Explanation

Answer: Option C Explanation:

No answer description available for this question.

6.

What will be the output of the program if the array begins at address 65486?

#include<stdio.h>
int main() { int arr[] = {12, 14, 15, 23, 45}; printf("%u, %u\n", arr, &arr); return 0; } A. C. 65486, 65488 65486, 65490 B. D. 65486, 65486

65486, 65487

Answer & Explanation

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 View Answer Workspace Report Discuss in Forum

7.

What will be the output of the program if the array begins at 65486 and each integer occupies 2 bytes?

#include<stdio.h>
int main() { int arr[] = {12, 14, 15, 23, 45}; printf("%u, %u\n", arr+1, &arr+1); return 0; } A. C. 65488, 65490 65488, 65496 B. D. 64490, 65492 64490, 65498

Answer & Explanation

Answer: Option C 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+1, &arr+1); Here, the base address(also the address of first element) of the array is 65486. => Here, arr is reference to arr has type "pointer to int". Therefore, arr+1 is pointing to second element of the array arr memory location. Hence 65486 + 2 bytes = 65488 => Then, &arr is "pointer to array of 5 ints". Therefore, &arr+1 denotes "5 ints * 2 bytes * 1 = 10 bytes". Hence, begining address 65486 + 10 = 65496. So, &arr+1 = 65496 Hence the output of the program is 65486, 65496 View Answer Workspace Report Discuss in Forum

8.

What will be the output of the program ?

#include<stdio.h>
int main() { float arr[] = {12.4, 2.3, 4.5, 6.7}; printf("%d\n", sizeof(arr)/sizeof(arr[0])); return 0; } A. C. 5 6 B. D. 4

Answer & Explanation

Answer: Option B Explanation: The sizeof function return the given variable. Example: float a=10; sizeof(a) is 4 bytes Step 1: float arr[] = {12.4, 2.3, 4.5, 6.7}; The variable arr is declared as an

floating point array and it is initialized with the values. Step 2: printf("%d\n", sizeof(arr)/sizeof(arr[0])); The variable arr has 4 elements. The size of the float variable is 4 bytes. Hence 4 elements x 4 bytes = 16 bytes

sizeof(arr[0]) is 4 bytes
Hence 16/4 is 4 bytes Hence the output of the program is '4'. View Answer Workspace Report Discuss in Forum

9.

What will be the output of the program if the array begins at 65472 and each integer occupies 2 bytes?

#include<stdio.h>
int main() { int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0}; printf("%u, %u\n", a+1, &a+1); return 0; } A. C. 65474, 65476 65480, 65488 B. D. 65480, 65496

65474, 65488

Answer & Explanation

Answer: Option B Explanation: Step 1: int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0}; The array a[3][4] is declared as an integer array having the 3 rows and 4 colums dimensions. Step 2: printf("%u, %u\n", a+1, &a+1); The base address(also the address of the first element) of array is 65472. For a two-dimensional array like a reference to array has type "pointer to array of 4 ints". Therefore, a+1 is pointing to the memory location of first element of the second row in array a. Hence 65472 + (4 ints * 2 bytes) = 65480 Then, &a has type "pointer to array of 3 arrays of 4 ints", totally 12 ints.

Therefore,&a+1 denotes "12 ints * 2 bytes * 1 = 24 bytes". Hence, begining address 65472 + 24 = 65496. So, &a+1 = 65496 Hence the output of the program is 65480, 65496 View Answer Workspace Report Discuss in Forum

10. What will be the output of the program ?

#include<stdio.h>
int main() { static int a[2][2] = {1, 2, 3, 4}; int i, j; static int *p[] = {(int*)a, (int*)a+1, (int*)a+2}; for(i=0; i<2; i++) { for(j=0; j<2; j++) { printf("%d, %d, %d, %d\n", *(*(p+i)+j), *(*(j+p)+i), *(*(i+p)+j), *(*(p+j)+i)); } } return 0; } A. 1, 1, 1, 1 - 2, 3, 2, 3 - 3, 2, 3, 2 - 4, 4, 4, 4 B. 1, 2, 1, 2 - 2, 3, 2, 3 - 3, 4, 3, 4 - 4, 2, 4, 2 C. 1, 1, 1, 1 - 2, 2, 2, 2 - 3, 3, 3, 3 - 4, 4, 4, 4 D. 1, 2, 3, 4 - 2, 3, 4, 1 - 3, 4, 1, 2 - 4, 1, 2, 3 1, 2, 3, 4, 1, 3, 2, 4, 1, 2, 3, 4, 1 3 2 4

A.

B.

1, 2, 3, 4,

2, 3, 4, 2,

1, 2, 3, 4,

2 3 4 2

C.

1, 2, 3, 4,

1, 2, 3, 4,

1, 2, 3, 4,

1 2 3 4

D.

1, 2, 3, 4,

2, 3, 4, 1,

3, 4, 1, 2,

4 1 2 3

Answer & Explanation

Answer: Option A Explanation:

No answer description available for this question.

11. What will be the output of the program ?

#include<stdio.h>
voif fun(int **p); int main() { int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 8, 7, 8, 9, 0}; int *ptr; ptr = &a[0][0]; fun(&ptr); return 0; } void fun(int **p) { printf("%d\n", **p); } A. C. 1 B. D. 2 4

Answer & Explanation

Answer: Option A Explanation: Step 1: int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 8, 7, 8, 9, 0}; The variable a is declared as an multidimensional integer array with size of 3 rows 4 columns. Step 2: int *ptr; The *ptr is a integer pointer variable. Step 3: ptr = &a[0][0]; Here we are assigning the base address of the array ato the pointer variable *ptr. Step 4: fun(&ptr); Now, the &ptr contains the base address of array a. Step 4: Inside the function fun(&ptr); The printf("%d\n", **p); prints the value '1'. because the *p contains the base address or the first element memory address of the array a (ie. a[0])

**p contains the value of *p memory location (ie. a[0]=1).


Hence the output of the program is '1' View Answer Workspace Report Discuss in Forum

12. What will be the output of the program ?

#include<stdio.h>
int main() { void fun(int, int[]); int arr[] = {1, 2, 3, 4}; int i; fun(4, arr); for(i=0; i<4; i++) printf("%d,", arr[i]); return 0; } void fun(int n, int arr[]) { int *p=0; int i=0; while(i++ < n) p = &arr[i]; *p=0; } A. C. 2, 3, 4, 5 0, 1, 2, 3 B. D. 1, 2, 3, 4

3, 2, 1 0

Answer & Explanation

Answer: Option B Explanation: Step 1: void fun(int, int[]); This prototype tells the compiler that the function fun() accepts one integer value and one array as an arguments and does not return anything. Step 2: int arr[] = {1, 2, 3, 4}; The variable a is declared as an integer array and it is initialized to

a[0] = 1, a[1] = 2, a[2] = 3, a[3] = 4


Step 3: int i; The variable i is declared as an integer type. Step 4: fun(4, arr); This function does not affect the output of the program. Let's skip this function. Step 5: for(i=0; i<4; i++) { printf("%d,", arr[i]); } The for loop runs untill the variable i is less than '4' and it prints the each value of array a. Hence the output of the program is 1,2,3,4 View Answer Workspace Report Discuss in Forum

13. What will be the output of the program ?

#include<stdio.h>
int main() { int a[5] = {5, 1, 15, 20, 25}; int i, j, m; i = ++a[1]; j = a[1]++; m = a[i++]; printf("%d, %d, %d", i, j, m); return 0; } A. C. 2, 1, 15 3, 2, 15 B. D. 1, 2, 5 2, 3, 20

Answer & Explanation

Answer: Option C Explanation: Step 1: int a[5] = {5, 1, 15, 20, 25}; The variable arr is declared as an integer array with a size of 5 and it is initialized to

a[0] = 5, a[1] = 1, a[2] = 15, a[3] = 20, a[4] = 25 .


Step 2: int i, j, m; The variable i,j,m are declared as an integer type. Step 3: i = ++a[1]; becomes i = ++1; Hence i = 2 and a[1] = 2 Step 4: j = a[1]++; becomes j = 2++; Hence j = 2 Step 5: m = a[i++]; becomes m = a[2]; Hence m = 15 and i is increemented by 1(i++ means 2++ so i=3) Step 6: printf("%d, %d, %d", i, j, m); It prints the value of the variables i, j, m Hence the output of the program is 3, 2, 15

C Programming :: Arrays
@ : Home > C Programming > Arrays > Point Out Correct Statements

1.

Which of the following is correct way to define the function fun() in the below program?

#include<stdio.h>
int main() { int a[3][4]; fun(a); return 0; }

A.

void fun(int p[][4]) { }

B.

void fun(int *p[4]) { }

C.

void fun(int *p[][4]) { }

D.

void fun(int *p[3][4]) { }

Answer & Explanation

Answer: Option A Explanation:

void fun(int p[][4]){ } is the correct way to write the function fun(). while the others are considered only the function fun() is called by using call by reference.
View Answer Workspace Report Discuss in Forum

2.

Which of the following statements are correct about an array? 1: The array int num[26]; can store 26 elements. 2: The expression num[1] designates the very first element in the array. 3: It is necessary to initialize the array at the time of declaration. 4: The declaration num[SIZE] is allowed if SIZE is a macro. 1,4

A. C.

1 2,3

B. D.

2,4

Answer & Explanation

Answer: Option B Explanation:

1. The array int num[26]; can store 26 elements. This statement is true. 2. The expression num[1] designates the very first element in the array. This statement is false, because it designates the second element of the array. 3. It is necessary to initialize the array at the time of declaration. This statement is false. 4. The declaration num[SIZE] is allowed if SIZE is a macro. This statement is true, because the MACRO just replaces the symbol SIZE with given value. Hence the statements '1' and '4' are correct statements. View Answer Workspace Report Discuss in Forum

3.

Which of the following statements are correct about 6 used in the program?

int num[6]; num[6]=21;


A. In the first statement 6 specifies a particular element, whereas in the second statement it specifies a type. In the first statement 6 specifies a array size, whereas in the second statement it specifies a particular element of array.

B.

C.

In the first statement 6 specifies a particular element, whereas in the second statement it specifies a array size. In both the statement 6 specifies array size.

D.

Answer & Explanation

Answer: Option B Explanation: The statement 'B' is correct, because int num[6]; specifies the size of array andnum[6]=21; designates the particular element(7th element) of the array. View Answer Workspace Report Discuss in Forum

4.

Which of the following statements mentioning the name of the array begins DOES NOT yield the base address? 1: When array name is used with the sizeof operator. 2: When array name is operand of the & operator. 3: When array name is passed to scanf() function. 4: When array name is passed to printf() function.

A. C.

A B

B. D.

A, B

B, D

Answer & Explanation

Answer: Option B Explanation: The statement 1 and 2 does not yield the base address of the array. While thescanf() and printf() yields the base address of the array. View Answer Workspace Report Discuss in Forum

5.

Which of the following statements are correct about the program below?

#include<stdio.h>
int main() { int size, i; scanf("%d", &size); int arr[size]; for(i=1; i<=size; i++) { scanf("%d", arr[i]); printf("%d", arr[i]); } return 0; } The code is erroneous since the subscript for array used in for loop is in the range 1 to size. The code is erroneous since the values of array are getting scanned through the loop. The code is erroneous since the statement declaring array is invalid.

A.

B. C. D.

The code is correct and runs successfully.

Answer & Explanation

Answer: Option C Explanation: The statement int arr[size]; produces an error. because we cannot initialize the size of array dynamically. Example: int arr[10];

C Programming :: Arrays
@ : Home > C Programming > Arrays > Yes / No Questions

1.

Does this mentioning array name gives the base address in all the contexts? A. Yes B. No

Answer & Explanation

Answer: Option B Explanation: No, Mentioning the array name in C or C++ gives the base address in all contexts except one. Syntactically, the compiler treats the array name as a pointer to the first element. You can reference elements using array syntax, a[n], or using pointer syntax,*(a+n), and you can even mix the usages within an expression. When you pass an array name as a function argument, you are passing the "value of the pointer", which means that you are implicitly passing the array by reference, even though all parameters in functions are "call by value". View Answer Workspace Report Discuss in Forum

2.

Are the expressions arr and &arr same for an array of 10 integers? A. Yes B. No

Answer & Explanation

Answer: Option B Explanation: Both mean two different things. arr gives the address of the first int, whereas the &arr gives the address of array of ints. View Answer Workspace Report Discuss in Forum

3.

A pointer to a block of memory is effectively same as an array A. True B. False

Answer & Explanation

Answer: Option A

Explanation: Yes, It is possible to allocate a block of memory (of arbitrary size) at run-time, using the standard library's malloc function, and treat it as an array. View Answer Workspace Report Discuss in Forum

4.

Is there any difference int the following declarations?

int fun(int arr[]); int fun(int arr[2]);


A. Yes B. No

Answer & Explanation

Answer: Option B Explanation: No, both the statements are same. It is the prototype for the function fun() that accepts one integer array as an parameter and returns an integer value.

You might also like