PRF 192, PRF192, PRF 192, PRF192-learn PROGRAMING, PRF192 - References 1, PRF192 - References 2, PRF192 - Unit 6-10, PRF192 - Unit 1-5, PRF192 - Unit 1-5, PRF192 - Unit 6-10
a
#include <stdio.h> int main() { char *var = "Advanced Training in C by Sanfoundry.com"; } Which of the following format identifier can never be used for the variable var? a) %f b) %d c) %c d) %s
d
What is the output of the following C code(on a 64 bit machine)? #include <stdio.h> union Sti { int nu; char m; }; int main() { union Sti s; printf("%d", sizeof(s)); return 0; } a) 8 b) 5 c) 9 d) 4
a
What is the output of this C code (on a 32-bit machine)? #include <stdio.h> int main() { int x = 10000; double y = 56; int *p = &x; double *q = &y; printf("p and q are %d and %d", sizeof(p), sizeof(q)); return 0; } a) p and q are 4 and 4 b) p and q are 4 and 8 c) Compiler error d) p and q are 2 and 8
b
What is the output of this C code? #include <stdio.h> #define MAX 2 enum bird {SPARROW = MAX + 1, PARROT = SPARROW + MAX}; int main() { enum bird b = PARROT; printf("%d\n", b); return 0; } a) Compilation error b) 5 c) Undefined value d) 2
c
What is the output of this C code? #include <stdio.h> #define a 10 int main() { const int a = 5; printf("a = %d\n", a); } a) a = 5 b) a = 10 c) Compilation error d) Runtime error
d
What is the output of this C code? #include <stdio.h> #include <string.h> int main() { char *str = "x"; char c = 'x'; char ary[1]; ary[0] = c; printf("%d %d", strlen(str), strlen(ary)); return 0; } a) 1 1 b) 2 1 c) 2 2 d) 1 (undefined value)
d
What is the output of this C code? #include <stdio.h> enum birds {SPARROW, PEACOCK, PARROT}; enum animals {TIGER = 8, LION, RABBIT, ZEBRA}; int main() { enum birds m = TIGER; int k; k = m; printf("%d\n", k); return 0; } a) 0 b) Compile time error c) 1 d) 8
b
What is the output of this C code? #include <stdio.h> int main() { const int p; p = 4; printf("p is %d", p); return 0; } a) p is 4 b) Compile time error c) Run time error d) p is followed by a garbage value
c
What is the output of this C code? #include <stdio.h> int main() { enum {ORANGE = 5, MANGO, BANANA = 4, PEACH}; printf("PEACH = %d\n", PEACH); } a) PEACH = 3 b) PEACH = 4 c) PEACH = 5 d) PEACH = 6
d
What is the output of this C code? #include <stdio.h> int main() { float x = 'a'; printf("%f", x); return 0; } a) a b) run time error c) a.0000000 d) 97.000000
a
What is the output of this C code? #include <stdio.h> int main() { int a = 10, b = 5, c = 3; b != !a; c = !!a; printf("%d\t%d", b, c); } a) 5 1 b) 0 3 c) 5 3 d) 1 1
b
What is the output of this C code? #include <stdio.h> int main() { int a = 10, b = 5, c = 5; int d; d = a == (b + c); printf("%d", d); } a) Syntax error b) 1 c) 10 d) 5
a
What is the output of this C code? #include <stdio.h> int main() { int a = 10; double b = 5.6; int c; c = a + b; printf("%d", c); } a) 15 b) 16 c) 15.6 d) 10
d
What is the output of this C code? #include <stdio.h> int main() { int a = 10; if (a == a--) printf("TRUE 1\t"); a = 10; if (a == --a) printf("TRUE 2\t"); } a) TRUE 1 b) TRUE 2 c) TRUE 1 TRUE 2 d) Compiler Dependent
b
What is the output of this C code? #include <stdio.h> int main() { int i = -3; int k = i % 2; printf("%d\n", k); } a) Compile time error b) -1 c) 1 d) Implementation defined
b
What is the output of this C code? #include <stdio.h> int main() { int i = -5; i = i / 3; printf("%d\n", i); return 0; } a) Implementation defined b) -1 c) -3 d) Compile time error
b
What is the output of this C code? #include <stdio.h> int main() { int i = 1; if (i++ && (i == 1)) printf("Yes\n"); else printf("No\n"); } a) Yes b) No c) Depends on the compiler d) Depends on the standard
b
What is the output of this C code? #include <stdio.h> int main() { int i = 23; char c = -23; if (i < c) printf("Yes\n"); else printf("No\n"); } a) Yes b) No c) Depends on the compiler d) Depends on the standard
b
What is the output of this C code? #include <stdio.h> int main() { int i = 3; int l = i / -2; int k = i % -2; printf("%d %d\n", l, k); return 0; } a) Compile time error b) -1 1 c) 1 -1 d) Implementation defined
b
What is the output of this C code? #include <stdio.h> int main() { int i = 5; i = i / 3; printf("%d\n", i); return 0; } a) Implementation defined b) 1 c) 3 d) Compile time error
b
What is the output of this C code? #include <stdio.h> int main() { int var = 010; printf("%d", var); } a) 2 b) 8 c) 9 d) 10
c
What is the output of this C code? #include <stdio.h> int main() { int x = 1, y = 0, z = 3; x > y ? printf("%d", z) : return z; } a) 3 b) 1 c) Compile time error d) Run time error
a
What is the output of this C code? #include <stdio.h> int main() { int y = 10000; int y = 34; printf("Hello World! %d\n", y); return 0; } a) Compile time error b) Hello World! 34 c) Hello World! 1000 d) Hello World! followed by a junk value
c
What is the output of this C code? #include <stdio.h> int main() { j = 10; printf("%d\n", j++); return 0; } a) 10 b) 11 c) Compile time error d) 0
c
What is the output of this C code? #include <stdio.h> int main() { printf("C programming %s", "Class by\n%s Sanfoundry", "WOW"); } a) C programming Class by WOW Sanfoundry b) C programming Class by\n%s Sanfoundry c) C programming Class by %s Sanfoundry d) Compilation error
c
What is the output of this C code? #include <stdio.h> int main() { printf("Hello World! %d \n", x); return 0; } a) Hello World! x; b) Hello World! followed by a junk value c) Compile time error d) Hello World!
b
What is the output of this C code? #include <stdio.h> int main() { printf("sanfoundry\r\nclass\n"); return 0; } a) sanfoundryclass b) sanfoundry class c) classundry d) sanfoundry
b
What is the output of this C code? #include <stdio.h> int main() { signed char chr; chr = 128; printf("%d\n", chr); return 0; } a) 128 b) -128 c) Depends on the compiler d) None of the mentioned
b
What is the output of this C code? #include <stdio.h> int main() { unsigned int i = 23; signed char c = -23; if (i > c) printf("Yes\n"); else if (i < c) printf("No\n"); } a) Yes b) No c) Depends on the compiler d) Depends on the operating system
a
What is the output of this C code? #include <stdio.h> void foo(const int *); int main() { const int i = 10; printf("%d ", i); foo(&i); printf("%d", i); } void foo(const int *i) { *i = 20; } a) Compile time error b) 10 20 c) Undefined value d) 10
d
What is the output of this C code? #include <stdio.h> void main() { double x = 123828749.66; int y = x; printf("%d\n", y); printf("%lf\n", y); } a) 0, 0.0 b) 123828749, 123828749.66 c) 12382874, 12382874.0 d) 123828749, 0.000000
a
What is the output of this C code? #include <stdio.h> void main() { float x = 0.1; if (x == 0.1) printf("Sanfoundry"); else printf("Advanced C Classes"); } a) Advanced C Classes b) Sanfoundry c) Run time error d) Compile time error
d
What is the output of this C code? #include <stdio.h> void main() { int a = 3; int b = ++a + a++ + --a; printf("Value of b is %d", b); } a) Value of x is 12 b) Value of x is 13 c) Value of x is 10 d) Undefined behaviour
a
What is the output of this C code? #include <stdio.h> void main() { int k = 4; float k = 4; printf("%d", k) } a) Compile time error b) 4 c) 4.0000000 d) 4.4
a
What is the output of this C code? #include <stdio.h> void main() { int x = 0, y = 2, z = 3; int a = x & y | z; printf("%d", a); } a) 3 b) 0 c) 2 d) Run time error
b
What is the output of this C code? #include <stdio.h> void main() { int x = 1, y = 0, z = 5; int a = x && y && z++; printf("%d", z); } a) 6 b) 5 c) 0 d) Varies
a
What is the output of this C code? #include <stdio.h> void main() { int x = 1, y = 0, z = 5; int a = x && y || z++; printf("%d", z); } a) 6 b) 5 c) 0 d) Varies
d
What is the output of this C code? #include <stdio.h> void main() { int x = 1, z = 3; int y = x << 3; printf(" %d\n", y); } a) -2147483648 b) -1 c) Run time error d) 8
c
What is the output of this C code? #include <stdio.h> int main() { printf("sanfoundry\rclass\n"); return 0; } a) sanfoundryclass b) sanfoundry class c) classundry d) sanfoundry
c
What is the output of this C code? (7 and 8 are entered) #include <stdio.h> void main() { float x; int y; printf("enter two numbers \n", x); scanf("%f %f", &x, &y); printf("%f, %d", x, y); } a) 7.000000, 7 b) Run time error c) 7.000000, junk d) Varies
d
What is the problem in following variable declaration? float 3Bedroom-Hall-Kitchen?; a) The variable name begins with an integer b) The special character '-' c) The special character '?' d) All of the mentioned
c
What is the size of an int data type? a) 4 Bytes b) 8 Bytes c) Depends on the system/compiler d) Cannot be determined
c
What is the value of x in this C code? #include <stdio.h> void main() { int x = 5 * 9 / 3 + 9; } a) 3.75 b) Depends on compiler c) 24 d) 3
b
What will be the value of d in the following program? #include <stdio.h> int main() { int a = 10, b = 5, c = 5; int d; d = b + c == a; printf("%d", d); } a) Syntax error b) 1 c) 5 d) 10
c
What will happen if the below program is executed? #include <stdio.h> int main() { int main = 3; printf("%d", main); return 0; } a) It will cause a compile-time error b) It will cause a run-time error c) It will run without any error and prints 3 d) It will experience infinite looping
c
When double is converted to float, the value is? a) Truncated b) Rounded c) Depends on the compiler d) Depends on the standard
a
Which among the following are the fundamental arithmetic operators, ie, performing the desired operation can be done using that operator only? a) +, - b) +, -, % c) +, -, *, / d) +, -, *, /, %
b
Which data type is most suitable for storing a number 65000 in a 32-bit system? a) signed short b) unsigned short c) long d) int
c
Which is correct with respect to size of the datatypes? a) char > int > float b) int > char > float c) char < int < double d) double > char > int
c
Which is false ? a) A variable defined once can be defined again with different scope b) A single variable cannot be defined with two different types in the same scope c) A variable must be declared and defined at the same time d) A variable refers to a location in memory
a
Which is false? a) Constant variables need not be defined as they are declared and can be defined later b) Global constant variables are initialised to zero c) const keyword is used to define constant values d) You cannot reassign a value to a constant variable
c
Which keyword is used to prevent any changes in the variable within a C program? a) immutable b) mutable c) const d) volatile
b
Which of the datatypes have size that is variable? a) int b) struct c) float d) double
a
Which of the following cannot be a variable name in C? a) volatile b) true c) friend d) export
d
Which of the following data type will throw an error on modulus operation(%)? a) char b) short c) int d) float
d
Which of the following declaration is illegal? a) char *str = "Best C programming classes by Sanfoundry"; b) char str[] = "Best C programming classes by Sanfoundry"; c) char str[20] = "Best C programming classes by Sanfoundry"; d) char[] str = "Best C programming classes by Sanfoundry";
a
Which of the following declaration is not supported by C? a) String str; b) char *str; c) float str = 3e2; d) Both (a) and (c)
d
Which of the following is a User-defined data type? a) typedef int Boolean; b) typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays; c) struct {char name[10], int age}; d) all of the mentioned
d
Which of the following is not a pointer declaration? a) char a[10]; b) char a[] = {'1', '2', '3', '4'}; c) char *str; d) char a;
d
Which of the following is not a valid C variable name? a) int number; b) float rate; c) int variable_count; d) int $main;
d
Which of the following is not a valid variable name declaration? a) float PI = 3.14; b) double PI = 3.14; c) int PI = 3.14; d) #define PI 3.14
d
Which of the following is not a valid variable name declaration? a) int __a3; b) int __3a; c) int __A3; d) None of the mentioned
c
Which of the following is not a valid variable name declaration? a) int _a3; b) int a_3; c) int 3_a; d) int _3a
c
Which of the following is true for variable names in C? a) They can contain alphanumeric characters as well as special characters b) It is not an error to declare a variable to be one of the keywords(like goto, static) c) Variable names cannot start with a digit d) Variable can be of any length
b
A variable declared in a function can be used in main a) True b) False c) True if it is declared static d) None of the mentioned
a
Relational operators cannot be used on: a) structure b) long c) strings d) float
b
The format identifier '%i' is also used for _____ data type? a) char b) int c) float d) double
d
What is the output of this C code? #include <stdio.h> void main() { int x = 5.3 % 2; printf("Value of x is %d", x); } a) Value of x is 2.3 b) Value of x is 1 c) Value of x is 0.3 d) Compile time error View Answer
a
What is the output of this C code? #include <stdio.h> void main() { int x = 97; char y = x; printf("%c\n", y); } a) a b) b c) 97 d) Run time error
a
What is the output of this C code? #include <stdio.h> void main() { int y = 3; int x = 5 % 2 * 3 / 2; printf("Value of x is %d", x); } a) Value of x is 1 b) Value of x is 2 c) Value of x is 3 d) Compile time error
d
Which among the following is NOT a logical or relational operator? a) != b) == c) || d) =
b
Which is valid C expression? a) int my_num = 100,000; b) int my_num = 100000; c) int my num = 1000; d) int $my_num = 10000;
c
Which of the following is not an arithmetic operation? a) a *= 10; b) a /= 10; c) a != 10; d) a %= 10;
a
enum types are processed by a) Compiler b) Preprocessor c) Linker d) Assembler
a
Variable name resolving (number of significant characters for uniqueness of variable) depends on a) Compiler and linker implementations b) Assemblers and loaders implementations c) C language d) None
c
Variable names beginning with underscore is not encouraged. Why? a) It is not standardized b) To avoid conflicts since assemblers and loaders use such names c) To avoid conflicts since library routines use such names d) To avoid conflicts with environment variables of an operating system
c
What is short int in C programming? a) Basic datatype of C b) Qualifier c) short is the qualifier and int is the basic datatype d) All of the mentioned
a
What is the final value of j in the below code? #include <stdio.h> int main() { int i = 0, j = 0; if (i && (j = i + 10)) //do something ; } a) 0 b) 10 c) Depends on the compiler d) Depends on language standard
a
What is the final value of j in the below code? #include <stdio.h> int main() { int i = 10, j = 0; if (i || (j = i + 10)) //do something ; } a) 0 b) 20 c) Compile time error d) Depends on language standard
a
Comment on the output of this C code? #include <stdio.h> int main() { float f1 = 0.1; if (f1 == 0.1f) printf("equal\n"); else printf("not equal\n"); } a) equal b) not equal c) Output depends on compiler d) None of the mentioned
b
Comment on the output of this C code? #include <stdio.h> int main() { int ThisIsVariableName = 12; int ThisIsVariablename = 14; printf("%d", ThisIsVariablename); return 0; } a) The program will print 12 b) The program will print 14 c) The program will have a runtime error d) The program will cause a compile-time error due to redeclaration
d
Comment on the output of this C code? #include <stdio.h> int main() { int a[5] = {1, 2, 3, 4, 5}; int i; for (i = 0; i < 5; i++) if ((char)a[i] == '5') printf("%d\n", a[i]); else printf("FAIL\n"); } a) The compiler will flag an error b) Program will compile and print the output 5 c) Program will compile and print the ASCII value of 5 d) Program will compile and print FAIL for 5 times
b
Comment on the output of this C code? #include <stdio.h> void main() { float x = 0.1; printf("%d, ", x); printf("%f", x); } a) 0.100000, junk value b) Junk value, 0.100000 c) 0, 0.100000 d) 0, 0.999999
d
Comment on the output of this C code? #include <stdio.h> void main() { int const k = 5; k++; printf("k is %d", k); } a) k is 6 b) Error due to const succeeding int c) Error, because a constant variable can be changed only twice d) Error, because a constant variable cannot be changed
c
Comment on the output of this C code? #include <stdio.h> void main() { int k = 4; int *const p = &k; int r = 3; p = &r; printf("%d", p); } a) Address of k b) Address of r c) Compile time error d) Adress of k + address of r
a
Does logical operators in C language are evaluated with short circuit? a) True b) False c) Depends on the compiler d) Depends on the standard
c
Does this compile without error? #include <stdio.h> int main() { for (int k = 0; k < 10; k++); return 0; } a) Yes b) No c) Depends on the C standard implemented by compilers d) None of the mentioned
a
Does this compile without error? #include <stdio.h> int main() { int k; { int k; for (k = 0; k < 10; k++); } } a) Yes b) No c) Depends on the compiler d) Depends on the C standard implemented by compilers
b
For the following code snippet: char *str = "Sanfoundry.com\0" "training classes"; The character pointer str holds reference to string: a) Sanfoundry.com b) Sanfoundry.com\0training classes c) Sanfoundry.comtraining classes d) Invalid declaration
a
All keywords in C are in a) LowerCase letters b) UpperCase letters c) CamelCase letters d) None
a
Are logical operators sequence points? a) True b) False c) Depends on the compiler d) Depends on the standard
b
Comment on the output of this C code? #include <stdio.h> int main() { const int i = 10; int *ptr = &i; *ptr = 20; printf("%d\n", i); return 0; } a) Compile time error b) Compile time warning and printf displays 20 c) Undefined behaviour d) 10
b
Comment on the output of this C code? #include <stdio.h> int main() { float f1 = 0.1; if (f1 == 0.1) printf("equal\n"); else printf("not equal\n"); } a) equal b) not equal c) Output depends on compiler d) None of the mentioned
b
C99 standard guarantees uniqueness of ____ characters for internal names. a) 31 b) 63 c) 12 d) 14
a
C99 standard guarantess uniqueness of _____ characters for external names. a) 31 b) 6 c) 12 d) 14
b
Comment on the output of this C code? #include <stdio.h> int const print() { printf("Sanfoundry.com"); return 0; } void main() { print(); } a) Error because function name cannot be preceded by const b) Sanfoundry.com c) Sanfoundry.com is printed infinite times d) Blank screen, no output
a
Comment on the output of this C code? #include <stdio.h> int main() { char c; int i = 0; FILE *file; file = fopen("test.txt", "w+"); fprintf(file, "%c", 'a'); fprintf(file, "%c", -1); fprintf(file, "%c", 'b'); fclose(file); file = fopen("test.txt", "r"); while ((c = fgetc(file)) != -1) printf("%c", c); return 0; } a) a b) Infinite loop c) Depends on what fgetc returns d) Depends on the compiler
b
Result of a logical or relational expression in C is a) True or False b) 0 or 1 c) 0 if expression is false and any positive number if expression is true d) None of the mentioned
b
The name of the variable used in one function cannot be used in another function a) True b) False c) May be d) None of the mentioned
a
The precedence of arithmetic operators is (from highest to lowest) a) %, *, /, +, - b) %, +, /, *, - c) +, -, %, *, / d) %, +, -, *, /