AmbitionBox
Discover Best Places to work in India
Discover best places to work
Compare & find best workplace
Bring your workplace to life
Highlight your company's perks
Read reviews for 6L+ companies
Rate your former or current company
Discover salaries for 8L+ companies
Calculate your take home salary
Check your market value
Help other jobseekers
Read interviews for 90K+ companies
Interviews questions for 1K+ colleges
Contribute your interview questions
C Programming
What will be the output of the program?
#include < stdio . h >#includeint main() { char dest[] = {97, 97, 0}; char src[] = "aaa"; int i; if((i = memcmp(dest, src, 2))==0) printf("Got it"); elseprintf("Missed"); return0; }
Missed
Got it
Error in memcmp statement
None of above
Option B
memcmp compares the first 2 bytes of the blocks dest and src as unsigned chars. So, the ASCII value of 97 is 'a'. if((i = memcmp(dest, src, 2))==0) When comparing the array dest and src as unsigned chars, the first 2 bytes are same in both variables.so memcmp returns '0'. Then, the if(0=0) condition is satisfied. Hence the output is "Got it".
Point out the error in the following program.
#include < stdio . h >int main() { fprintf("Ambition Box"); printf("%.ef", 2.0); return0; }
Error: unknown value in printf() statement.
Error: in fprintf() statement.
No error and prints "Ambition Box"
No error and prints "2.0"
Declaration Syntax: int fprintf (FILE *stream, const char *format [, argument, ...]);Example: fprintf(filestream, "%s %d %s", Name, Age, City);
#include < stdio . h >#include < string . h >int main() { char str1[] = "Learn through Ambition Box\0.com", str2[120]; char *p; p = (char*) memccpy(str2, str1, 'i', strlen(str1)); *p = '\0'; printf("%s", str2); return0; }
Error: in memccpy statement
Error: invalid pointer conversion
Error: invalid variable declaration
No error and prints "Learn through Ambi"
Option D
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
#include < stdio . h >int main() { char str[] = "Ambition box"; printf("%.#s %2s", str, str); return0; }
Error: in Array declaration
Error: printf statement
Error: unspecified character in printf
No error
How many times "Ambition Box" is get printed?
#includeint main() { int x; for(x=-1; x<=10; x++) { if(x < 5) continue; elsebreak; printf("Ambition Box"); } return0; }
Infinite times
11 times
0 times
10 times
Option C
How many times the while loop will get executed if a short int is 2 byte wide?
#includeint main() { int j=1; while(j <= 255) { printf("%c %d\n", j, j); j++; } return0; }
255 times
256 times
254 times
Answer :
Explanation :
The while(j <= 255) loop will get executed 255 times. The size short int(2 byte wide) does not affect the while() loop.
Which of the following is not logical operator?
&
&&
||
!
Option A
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.
In mathematics and computer programming, which is the correct order of mathematical operators ?
Addition, Subtraction, Multiplication, Division
Division, Multiplication, Addition, Subtraction
Multiplication, Addition, Division, Subtraction
Addition, Division, Modulus, Subtraction
Simply called as BODMAS (Brackets, Order, Division, Multiplication, Addition and Subtraction). Mnemonics are often used to help students remember the rules, but the rules taught by the use of acronyms can be misleading. In the United States the acronym PEMDAS is common. It stands for Parentheses, Exponents, Multiplication, Division, Addition, Subtraction. In other English speaking countries, Parentheses may be called Brackets, or symbols of inclusion and Exponentiation may be called either Indices, Powers or Orders, and since multiplication and division are of equal precedence, M and D are often interchanged, leading to such acronyms as BEDMAS, BIDMAS, BODMAS, BERDMAS, PERDMAS, and BPODMAS.
#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); return0; }
b = 300 c = 200
b = 100 c = garbage
b = 300 c = garbage
b = 100 c = 200
Initially variables a = 500, b = 100 and c is not assigned.Step 1: if(!a >= 400)Step 2: if(!500 >= 400)Step 3: if(0 >= 400)Step 4: if(FALSE) Hence the if condition is failed.Step 5: So, variable c is assigned to a value '200'.Step 6: printf("b = %d c = %d\n", b, c); It prints value of b and c. Hence the output is "b = 100 c = 200"
#include<stdio.h>int main() { unsignedint i = 65535; /* Assume 2 byte integer*/while(i++ != 0) printf("%d",++i); printf("\n"); return0; }
Infinite loop
0 1 2 ... 65535
0 1 2 ... 32767 - 32766 -32765 -1 0
No output
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 the printf("%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 it is an 'Infinite loop'.
Join India’s largest community to research company culture
Are you a student or working professional?
Student/Never worked
I am a student/I have never worked
Working Professional
I am working/I have worked before
What are your preferred job locations?
Popular Cities
Other Cities
Follow your preferred designations/job profiles
Suggestions based on your job profile
vs
Similar Companies