C Programming Test 1 . A preprocessor directive is a message from programmer to the preprocessor. A . Tru e B . Fal se Answer: Option A Explanation: True, the programmer tells the compiler to include the preprocessor when compiling. Learn more problems on : C Preprocessor Discuss about this problem : Discuss in Forum 2 . 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 C . 4, 4 D . Output may vary from compiler to compiler Answer: Option D Explanation: The order of evaluation of arguments passed to a function call
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
C Programming Test1.A preprocessor directive is a message from programmer to the preprocessor.
A.True B.False
Answer: Option A
Explanation:
True, the programmer tells the compiler to include the preprocessor when compiling.
Learn more problems on : C Preprocessor
Discuss about this problem : Discuss in Forum 2.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
C.4, 4
D.Output may vary from compiler to compiler
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.
In TurboC, the output will be 4, 3.
In GCC, the output will be 4, 4.
Learn more problems on : Expressions
Discuss about this problem : Discuss in Forum 3.Consider the following program and what will be content of t?
A typedef gives a new name to an existing data type. So err is a new name for enum error.
Learn more problems on : Declarations and Initializations
Discuss about this problem : Discuss in Forum 8.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;}
The keyword continue cannot be used in switch case. It must be used in for or while or do while loop. If there is any looping statement in switch case then we can use continue.
Learn more problems on : Control Instructions
Discuss about this problem : Discuss in Forum 9.What is the output of the program in Turbo C (in DOS 16-bit OS)?
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.
Since C is a compiler dependent language, it may give different output in ohter platforms. The above program works fine in Windows (TurboC), but error in Linux (GCC Compiler).
Learn more problems on : Declarations and Initializations
Discuss about this problem : Discuss in Forum 10.In the following program add a statement in the function fun() such that address of a gets
stored in j?
#include<stdio.h>int main(){ int *j; void fun(int**);
B.Print the contents of file "myfile.c" upto NULL character
C.Infinite loop
D.Error in program
Answer: Option C
Explanation:
The program will generate infinite loop. When an EOF is encountered fgetc() returns EOF. Instead of checking the condition for EOF we have checked it for NULL. so the program will generate infinite loop.
Learn more problems on : Input / Output
Discuss about this problem : Discuss in Forum 12.Can I increase the size of statically allocated array?
Discuss about this problem : Discuss in Forum 13.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.1 B.10
C.0 D.6
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 variable arr.
Hence the output of the program is 10.
Learn more problems on : Arrays
Discuss about this problem : Discuss in Forum 14.When we mention the prototype of a function?
A.Defining B.Declaring
C.Prototyping D.Calling
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.
Learn more problems on : Declarations and Initializations
Discuss about this problem : Discuss in Forum 15.Which of the following statements should be used to obtain a remainder after dividing 3.14 by
2.1 ?A.rem = 3.14 % 2.1;
B.rem = modf(3.14, 2.1);
C.rem = fmod(3.14, 2.1);
D.Remainder cannot be obtain in floating point division.
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
Learn more problems on : Declarations and Initializations
Discuss about this problem : Discuss in Forum 16.What will be the output of the program?
#include<stdio.h>#define MAX(a, b) (a > b ? a : b)
int main(){ int x; x = MAX(3+2, 2+7); printf("%d\n", x); return 0;}
Discuss about this problem : Discuss in Forum 1. 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 = 103 : The ; after the if(x!=y) will NOT produce an error.4 : The program will not produce output.
Discuss about this problem : Discuss in Forum 2.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.200 B.30
C.100 D.500
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 variable num 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'
Learn more problems on : Expressions
Discuss about this problem : Discuss in Forum 3.Point out the error in the following program.
C:\>myprogram.exeSundar2555.50scanf : floating point formats not linkedAbnormal program termination
The program terminates abnormally at the time of entering the float value for e[i].sal.
Solution:
Just add the following function in your program. It will force the compiler to include required libraries for handling floating point linkages.
static void force_fpf() /* A dummy function */{ float x, *y; /* Just declares two variables */ y = &x; /* Forces linkage of FP formats */ x = *y; /* Suppress warning message about x */}
Learn more problems on : Floating Point Issues
Discuss about this problem : Discuss in Forum 4.The keyword used to transfer control from a function back to the calling function is
A.switch B.goto
C.go back D.return
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 */
Error in statement k++. We cannot perform arithmetic on void pointers.
The following error will be displayed while compiling above program in TurboC.
Compiling PROGRAM.C:Error PROGRAM.C 8: Size of the type is unknown or zero.
Learn more problems on : Pointers
Discuss about this problem : Discuss in Forum 8.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. 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.
Learn more problems on : Arrays
Discuss about this problem : Discuss in Forum 9.The library function used to find the last occurrence of a character in a string is
A.strnstr() B.laststr()
C.strrchr() D.strstr()
Answer: Option C
Explanation:
Declaration: char *strrchr(const char *s, int c);
It scans a string s in the reverse direction, looking for a specific character c.
Example:
#include <string.h>#include <stdio.h>
int main(void){ char text[] = "I learn through IndiaBIX.com"; char *ptr, c = 'i';
ptr = strrchr(text, c); if (ptr) printf("The position of '%c' is: %d\n", c, ptr-text);
Discuss about this problem : Discuss in Forum 7.How many times the program will print "IndiaBIX" ?
#include<stdio.h>
int main(){ printf("IndiaBIX"); main(); return 0;}
A.Infinite times B.32767 times
C.65535 times D.Till stack doesn't overflow
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.
Learn more problems on : Functions
Discuss about this problem : Discuss in Forum 8.What will be the output of the program?
#include<stdio.h>#define SQR(x)(x*x)
int main(){ int a, b=3; a = SQR(b+2); printf("%d\n", a); return 0;}
The scanf function returns the number of input is given.
printf("%d\n", scanf("%d", &i)); The scanf function returns the value 1(one).
Therefore, the output of the program is '1'.
Learn more problems on : Input / Output
Discuss about this problem : Discuss in Forum 12.Point out the error in the program?
#include<stdio.h>#include<stdlib.h>
int main(){ unsigned char; FILE *fp; fp=fopen("trial", "r"); if(!fp) { printf("Unable to open file"); exit(1); } fclose(fp); return 0;}
A.Error: in unsigned char statement
B.Error: unknown file pointer
C.No error
D.None of above
Answer: Option C
Explanation:
This program tries to open the file trial.txt in read mode. If file not exists or unable to read it prints "Unable to open file" and then terminate the program.
If file exists, it simply close the file and then terminates the program.
m = ++i && ++j || ++k; printf("%d, %d, %d, %d\n", i, j, k, m); return 0;}
A.1, 2, 0, 1 B.-3, 2, 0, 1
C.-2, 3, 0, 1 D.2, 3, 1, 1
Answer: Option C
Explanation:
Step 1: int i=-3, j=2, k=0, m; here variable i, j, k, m are declared as an integer type and variable i, j, k are initialized to -3, 2, 0 respectively.
Step 2: m = ++i && ++j || ++k;becomes m = (-2 && 3) || ++k;becomes m = TRUE || ++k;. (++k) is not executed because (-2 && 3) alone return TRUE.Hence this statement becomes TRUE. So it returns '1'(one). Hence m=1.
Step 3: printf("%d, %d, %d, %d\n", i, j, k, m); In the previous step the value of i,j are increemented by '1'(one).
Hence the output is "-2, 3, 0, 1".
Learn more problems on : Expressions
Discuss about this problem : Discuss in Forum 3.What will be the output of the program?
#include<stdio.h>
int addmult(int ii, int jj){ int kk, ll; kk = ii + jj; ll = ii * jj; return (kk, ll);}
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 main(){ int *c; c = check(10, 20); printf("%d\n", c); return 0;}int *check(static int i, static int j){ int *p, *q; p = &i; q = &j; if(i >= 45) return (p); else return (q);}
A.10
B.20
C.Error: Non portable pointer conversion
D.Error: cannot use static for function parameters
Discuss about this problem : Discuss in Forum 6.If the size of integer is 4bytes, What will be the output of the program?
#include<stdio.h>
int main(){ int arr[] = {12, 13, 14, 15, 16}; printf("%d, %d, %d\n", sizeof(arr), sizeof(*arr), sizeof(arr[0])); return 0;}
A.10, 2, 4 B.20, 4, 4
C.16, 2, 2 D.20, 2, 2
Answer: Option B
Learn more problems on : Pointers
Discuss about this problem : Discuss in Forum 7.In the following program add a statement in the function fact() such that the factorial gets
stored in j.
#include<stdio.h>void fact(int*);
int main(){ int i=5; fact(&i); printf("%d\n", i); return 0;}void fact(int *j){ static int s=1; if(*j!=0) { s = s**j; *j = *j-1; fact(j); /* Add a statement here */ }}
Discuss about this problem : Discuss in Forum 11.If a char is 1 byte wide, an integer is 2 bytes wide and a long integer is 4 bytes wide then will
the following structure always occupy 7 bytes?
struct ex{ char ch; int i; long int a;};
A.Yes B.No
Answer: Option B
Explanation:
A compiler may leave holes in structures by padding the first char in the structure with another byte just to ensures that the integer that follows is stored at an location. Also, there might be 2extra bytes after the integer to ensure that the long integer is stored at an address, which is multiple of 4. Such alignment is done by machines to improve the efficiency of accessing values.
Learn more problems on : Structures, Unions, Enums
Discuss about this problem : Discuss in Forum 12.Point out the error/warning in the program?
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.
Learn more problems on : Control Instructions
Discuss about this problem : Discuss in Forum 2.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, 3, 1, 1 B.2, 3, 1, 2
C.1, 2, 3, 1 D.3, 3, 1, 2
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".
Learn more problems on : Expressions
Discuss about this problem : Discuss in Forum 3.In a function two return statements should never occur.
Discuss about this problem : Discuss in Forum 5.How many bytes are occupied by near, far and huge pointers (DOS)?
A.near=2 far=4 huge=4 B.near=4 far=8 huge=8
C.near=2 far=4 huge=8 D.near=4 far=4 huge=8
Answer: Option A
Explanation:
near=2, far=4 and huge=4 pointers exist only under DOS. Under windows and Linux every pointers is 4 bytes long.
Learn more problems on : Pointers
Discuss about this problem : Discuss in Forum 6.What will be the output of the program ?
#include<stdio.h>
int main(){ int x=30, *y, *z; y=&x; /* Assume address of x is 500 and integer is 4 byte size */ z=y; *y++=*z++; x++; printf("x=%d, y=%d, z=%d\n", x, y, z); return 0;}
A.x=31, y=502, z=502 B.x=31, y=500, z=500
C.x=31, y=498, z=498 D.x=31, y=504, z=504
Answer: Option D
Learn more problems on : Pointers
Discuss about this problem : Discuss in Forum 7.What will be the output of the program ?
#include<stdio.h>
int main(){ void *vp; char ch=74, *cp="JACK"; int j=65;
The struct emp is mentioned in the prototype of the function modify() before declaring the structure.To solve this problem declare struct emp before the modify() prototype.
Learn more problems on : Structures, Unions, Enums
Discuss about this problem : Discuss in Forum 13.The '.' operator can be used access structure elements using a structure variable.
A.True B.False
Answer: Option A
Learn more problems on : Structures, Unions, Enums
Discuss about this problem : Discuss in Forum 14.Can we specify a variable filed width in a scanf() format string?
A.Yes B.No
Answer: Option B
Explanation:
In scanf() a * in a format string after a % sign is used for the suppression of assignment. That is, the current input field is scanned but not stored.
Learn more problems on : Input / Output
Discuss about this problem : Discuss in Forum 15.Which header file should be included to use functions like malloc() and calloc()?
A.memory.h B.stdlib.h
C.string.h D.dos.h
Answer: Option B
Learn more problems on : Memory Allocation
Discuss about this problem : Discuss in Forum 16.If malloc() successfully allocates memory it returns the number of bytes it has allocated.
The malloc() function shall allocate unused space for an object whose size in bytes is specified by size and whose value is unspecified.
The order and contiguity of storage allocated by successive calls to malloc() is unspecified. The pointer returned if the allocation succeeds shall be suitably aligned so that it may be assigned to a pointer to any type of object and then used to access such an object in the space allocated (until the space is explicitly freed or reallocated). Each such allocation shall yield a pointer to an object disjoint from any other object. The pointer returned points to the start (lowest byte address) of the allocated space. If the space cannot be allocated, a null pointer shall be returned. If the size of the space requested is 0, the behavior is implementation-defined: the value returned shall be either a null pointer or a unique pointer.
Learn more problems on : Memory Allocation
Discuss about this problem : Discuss in Forum 17.In a function that receives variable number of arguments the fixed arguments passed to the
function can be at the end of argument list.A.True B.False
Answer: Option B
Learn more problems on : Variable Number of Arguments
Discuss about this problem : Discuss in Forum 18.We can allocate a 2-Dimensional array dynamically.
A.True B.False
Answer: Option A
Learn more problems on : Complicated Declarations
Discuss about this problem : Discuss in Forum 19.Are the following declarations same?
Discuss about this problem : Discuss in Forum 20.What is the purpose of fflush() function.
A.flushes all streams and specified streams.
B.flushes only specified stream.
C.flushes input/output buffer.
D.flushes file buffer.
Answer: Option A
Explanation:
"fflush()" flush any buffered output associated with filename, which is either a file opened for writing or a shell command for redirecting output to a pipe or coprocess.
Example: fflush(FilePointer);fflush(NULL); flushes all streams.
Learn more problems on : Library Functions
Discuss about this problem : Discuss in Forum 1. 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;}
A.1 ... 65535 B.Expression syntax error
C.No output D.0, 1, 2, 3, 4, 5
Answer: Option A
Explanation:
for(i<=5 && i>=-1; ++i; i>0) so expression i<=5 && i>=-1 initializes for loop. 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)
Learn more problems on : Control Instructions
Discuss about this problem : Discuss in Forum 2.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.Hi B.Hello
C.Hi Hello D.None of above
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:
1: Every if-else statement can be replaced by an equivalent statements using ? ; operators2: 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
C.1, 2 and 4 D.2, 3, 4
Answer: Option D
Learn more problems on : Control Instructions
Discuss about this problem : Discuss in Forum 4.Can we use a switch statement to switch on strings?
A.Yes B.No
Answer: Option B
Explanation:
The cases in a switch must either have integer constants or constant expressions.
Learn more problems on : Control Instructions
Discuss about this problem : Discuss in Forum 5.What will be the output of the program?
sizeof(str) denotes 6 * 4 bytes = 24 bytes. Hence it prints '24'
strlen(str[0])); becomes strlen(Frogs)). Hence it prints '5';
Hence the output of the program is 24, 5
Hint: If you run the above code in 16 bit platform (Turbo C under DOS) the output will be 12, 5. Because the pointer occupies only 2 bytes. If you run the above code in Linux (32 bit platform), the output will be 24, 5 (because the size of pointer is 4 bytes).
Learn more problems on : Strings
Discuss about this problem : Discuss in Forum 14.Point out the error in the program?
#include<stdio.h>
int main(){ FILE *fp; fp=fopen("trial", "r"); fseek(fp, "20", SEEK_SET); fclose(fp);
stdio.h, which stands for "standard input/output header", is the header in the C standard library that contains macro definitions, constants, and declarations of functions and types used for various standard input and output operations.
Learn more problems on : Library Functions
Discuss about this problem : Discuss in Forum 20.What will be the output of the program?
#include<stdio.h>
int main(){ int i; char c; for(i=1; i<=5; i++) { scanf("%c", &c); /* given input is 'a' */ printf("%c", c); ungetc(c, stdin); } return 0;}
A.aaaa B.aaaaa
C.Garbage value. D.Error in ungetc statement.
Answer: Option B
Explanation:
for(i=1; i<=5; i++) Here the for loop runs 5 times.
Loop 1: scanf("%c", &c); Here we give 'a' as input. printf("%c", c); prints the character 'a' which is given in the previous "scanf()" statement. ungetc(c, stdin); "ungetc()" function pushes character 'a' back into input stream.
Loop 2: Here the scanf("%c", &c); get the input from "stdin" because of "ungetc" function. printf("%c", c); Now variable c = 'a'. So it prints the character 'a'. ungetc(c, stdin); "ungetc()" function pushes character 'a' back into input stream.
This above process will be repeated in Loop 3, Loop 4, Loop 5.
Learn more problems on : Library Functions
Discuss about this problem : Discuss in Forum 1. A short integer is at least 16 bits wide and a long integer is at least 32 bits wide.
A.True B.False
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).
Learn more problems on : Control Instructions
Discuss about this problem : Discuss in Forum 2.Which of the following correctly shows the hierarchy of arithmetic operations in C?
A./ + * - B.* - / +
C.+ - / * D./ * + -
Answer: Option D
Explanation:
Simply called as BODMAS (Bracket of Division, Multiplication, Addition and Subtraction).
How Do I Remember ? BODMAS !
B - Brackets first O - Orders (ie Powers and Square Roots, etc.) DM - Division and Multiplication (left-to-right) AS - Addition and Subtraction (left-to-right)
Learn more problems on : Expressions
Discuss about this problem : Discuss in Forum 3.In which order do the following gets evaluated
Discuss about this problem : Discuss in Forum 4.Associativity has no role to play unless the precedence of operator is same.
A.True B.False
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 = 5 or 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.
Learn more problems on : Expressions
Discuss about this problem : Discuss in Forum 5.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 (on intel machine)?
int i; p = (char*)&a; for(i=0; i<=3; i++) printf("%02x\n", (unsigned char)p[i]); return 0;}
A.40 AC 00 00 B.04 CA 00 00
C.00 00 AC 40 D.00 00 CA 04
Answer: Option C
Learn more problems on : Floating Point Issues
Discuss about this problem : Discuss in Forum 6.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.ABCD
B.DCBA
C.0xABCD
D.Depends on big endian or little endian architecture
Answer: Option D
Learn more problems on : Floating Point Issues
Discuss about this problem : Discuss in Forum 7.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;
The macro function SQUARE(x) x*x calculate the square of the given number 'x'. (Eg: 102)
Step 1: float s=10, u=30, t=2, a; Here the variable s, u, t, a are declared as an floating point type and the variable s, u, t are initialized to 10, 30, 2.
Step 2: a = 2*(s-u*t)/SQUARE(t); becomes,
=> a = 2 * (10 - 30 * 2) / t * t; Here SQUARE(t) is replaced by macro to t*t .
=> a = 2 * (10 - 30 * 2) / 2 * 2;
=> a = 2 * (10 - 60) / 2 * 2;
=> a = 2 * (-50) / 2 * 2 ;
=> a = 2 * (-25) * 2 ;
=> a = (-50) * 2 ;
=> a = -100;
Step 3: printf("Result=%f", a); It prints the value of variable 'a'.
Hence the output of the program is -100
Learn more problems on : C Preprocessor
Discuss about this problem : Discuss in Forum 10.Preprocessor directive #undef can be used only on a macro that has been #define earlier
A.True B.False
Answer: Option A
Explanation:
True, #undef can be used only on a macro that has been #define earlier
Step 1: void swap(char *, char *); This prototype tells the compiler that the function swap accept two strings as arguments and it does not return anything.
Step 2: char *pstr[2] = {"Hello", "IndiaBIX"}; The variable pstr is declared as an pointer to the array of strings. It is initialized to
pstr[0] = "Hello", pstr[1] = "IndiaBIX"
Step 3: swap(pstr[0], pstr[1]); The swap function is called by "call by value". Hence it does not affect the output of the program.
If the swap function is "called by reference" it will affect the variable pstr.
Step 4: printf("%s\n%s", pstr[0], pstr[1]); It prints the value of pstr[0] and pstr[1].
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.1, 1, 1, 1 B.1, 1, 0, 1
C.1, 0, 0, 1 D.1, 0, 1, 1
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".
Learn more problems on : Expressions
Discuss about this problem : Discuss in Forum 5.Are the following two statement same?
1. a <= 20 ? b = 30: c = 30;2. (a <=20) ? b : c = 30;
A.Yes B.No
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,
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.
int main(){ char sentence[80]; int i; printf("Enter a line of text\n"); gets(sentence); for(i=strlen(sentence)-1; i >=0; i--) putchar(sentence[i]); return 0;}
A.The sentence will get printed in same order as it entered
B.The sentence will get printed in reverse order
C.Half of the sentence will get printed
D.None of above
Answer: Option B
Learn more problems on : Strings
Discuss about this problem : Discuss in Forum 12.What will be the output of the program ?
The file source.txt is opened in read mode and target.txt is opened in write mode. The file source.txt contains "To err is human".
Inside the while loop,
ch=getc(fs); The first character('T') of the source.txt is stored in variable ch and it's checked for EOF.
if(ch==EOF) If EOF(End of file) is true, the loop breaks and program execution stops.
If not EOF encountered, fseek(fs, 4L, SEEK_CUR); the file pointer advances 4 character from the current position. Hence the file pointer is in 5th character of file source.txt.
fputc(ch, ft); It writes the character 'T' stored in variable ch to target.txt.
The while loop runs three times and it write the character 1st and 5th and 11th characters ("Trh") in the target.txt file.
Learn more problems on : Input / Output
Discuss about this problem : Discuss in Forum 16.What will be the output of the program (sample.c) given below if it is executed from the
=> 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
Learn more problems on : Arrays
Discuss about this problem : Discuss in Forum 8.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: 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.
Learn more problems on : Arrays
Discuss about this problem : Discuss in Forum 9.What will be the output of the program ?
B.Print the contents of file "myfile.c" upto NULL character
C.Infinite loop
D.Error in program
Answer: Option C
Explanation:
The program will generate infinite loop. When an EOF is encountered fgetc() returns EOF. Instead of checking the condition for EOF we have checked it for NULL. so the program will generate infinite loop.
Learn more problems on : Input / Output
Discuss about this problem : Discuss in Forum 13.While calling the fprintf() function in the format string conversion specifier %s can be used to
write a character string in capital letters.A.True B.False
Declaration:void *memccpy(void *dest, const void *src, int c, size_t n); : Copies a block of n bytes from src to dest
With memccpy(), the copying stops as soon as either of the following occurs:=> the character 'i' is first copied into str2=> n bytes have been copied into str2
Learn more problems on : Library Functions
Discuss about this problem : Discuss in Forum 20.Point out the error in the following program.
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.
Learn more problems on : Floating Point Issues
Discuss about this problem : Discuss in Forum 4.What will be the output of the program?
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.
Learn more problems on : Floating Point Issues
Discuss about this problem : Discuss in Forum 5.If a function contains two return statements successively, the compiler will generate warnings.
Yes/No ?A.Yes B.No
Answer: Option A
Explanation:
Yes. If a function contains two return statements successively, the compiler will generate "Unreachable code" warnings.
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
Learn more problems on : Functions
Discuss about this problem : Discuss in Forum 6.Point out the error in the program
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'.
Learn more problems on : Arrays
Discuss about this problem : Discuss in Forum 8.Is there any difference int the following declarations?
int fun(int arr[]);int fun(int arr[2]);
A.Yes B.No
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.
Learn more problems on : Arrays
Discuss about this problem : Discuss in Forum 9.What will be the output of the program (Turbo C in 16 bit platform DOS) ?
It prints 'IndiaBIX IndiaBIX' in TurboC (in 16 bit platform).
It may cause a 'segmentation fault error' in GCC (32 bit platform).
Learn more problems on : Strings
Discuss about this problem : Discuss in Forum 10.Which of the following statements correct about the below program?
#include<stdio.h>
int main(){ union a { int i; char ch[2]; }; union a u1 = {512}; union a u2 = {0, 2}; return 0;}1: u2 CANNOT be initialized as shown.2: u1 can be initialized as shown.3: To initialize char ch[] of u2 '.' operator should be used.4: The code causes an error 'Declaration syntax error'
A.1, 2 B.2, 3
C.1, 2, 3 D.1, 3, 4
Answer: Option C
Learn more problems on : Structures, Unions, Enums
Discuss about this problem : Discuss in Forum 11.Does there exist any way to make the command-line arguments available to other functions
without passing them as arguments to the function?A.Yes B.No
No. It will print something like 'IndiaBIX(some garbage values here)' .
Because after copying the first 8 characters of source string into target string strncpy() doesn't terminate the target string with a '\0'. So it may print some garbage values along with IndiaBIX.