C & C++ Past Paper PDF

Summary

This document appears to be a collection of C and C++ programming questions suitable for a secondary school examination or practice exercises. The questions explore various elements of programming, including variable naming, expressions, declarations, loops, functions, pointers, and memory allocation.

Full Transcript

Question Content Option1 Option2 Option3 Option4 Correct Which of the following is not a valid C variable name? Int number; Float rate;...

Question Content Option1 Option2 Option3 Option4 Correct Which of the following is not a valid C variable name? Int number; Float rate; Int variable_count; Int $main; Int $main; All keywords in C are in ____________ Lowercase letters Uppercase letters Camelcase letters None of the mentioned Lowercase letters Which is valid C expression? Int my_num = 100,000; Int my_num = 100000; Int my num = 1000; Int $my_num = 10000; Int my_num = 100000; Which of the following cannot be a variable name in C? Volatile TRUE Friend Export Volatile What is short int in C programming? The basic data type of c Qualifier Short is the qualifier and int is All of the mentioned Short is the qualifier and int is the basic data type the basic data type Which of the following declaration is not supported by C language? String str; Char *str; Float str = 3e2; Both “string str;” and “float str = String str; 3e2;” Which keyword is used to prevent any changes in the variable within a C program? Immutable Mutable Const Volatile Const What is the result of logical or relational expression in C? True or false 0 or 1 0 if an expression is false and any None of the mentioned 0 or 1 positive number if an expression is true Which of the following typecasting is accepted by C language? Widening conversions Narrowing conversions Widening & narrowing None of the mentioned Narrowing conversions conversions Where in C the order of precedence of operators do not exist? If, else Do-while Within a macro definition None of the mentioned None of the mentioned What is an example of iteration in C? For While Do-while All of the mentioned All of the mentioned Functions can return enumeration constants in C? TRUE FALSE Depends on the compiler Depends on the standard TRUE Functions in C Language are always _________ Internal External Both internal and external External and internal are not External valid terms for functions Which of following is not accepted in C? Static a = 10; //static as Static int func (int); //parameter as Static static int a; //a static All of the mentioned Static static int a; //a static static variable prefixed with static variable prefixed with static Property which allows to produce different executable for different platforms in C is File inclusion Selective inclusion Conditional compilation Recursive macros Conditional compilation called? What is #include ? Preprocessor directive Inclusion directive File inclusion directive None of the mentioned Preprocessor directive C preprocessors can have compiler specific features. TRUE FALSE Depends on the standard Depends on the platform TRUE Which of the following are C preprocessors? #ifdef #define #endif All of the mentioned All of the mentioned The C-preprocessors are specified with _________ symbol. # $ ”” & # How many number of pointer (*) does C have against a pointer variable declaration? 7 127 255 No limits No limits Which of the following return-type cannot be used for a function in C? Char * Struct Void None of the mentioned None of the mentioned What is the sizeof(char) in a 32-bit C compiler? 1 bit 2 bits 1 byte 2 bytes 1 byte Which of the following is not an operator in C? ,(comma) Sizeof() ~ None of the mentioned None of the mentioned scanf() is a predefined function in______header file. Stdlib. h Ctype. h Stdio. h Stdarg. h Stdio. h Which of the following is not a valid variable name declaration? Int __a3; Int __3a; Int __a3; None of the mentioned None of the mentioned Which of the following is not a valid C variable name? Int number; Float rate; Int variable_count; Int $main; Int $main; Which of the following is not a valid variable name declaration? Float pi = 3.14; Double pi = 3.14; Int pi = 3.14; #define pi 3.14 #define pi 3.14 What is the problem in the following variable declaration? float 3Bedroom-Hall- The variable name begins with an The special character ‘-‘ The special character ‘?’ All of the mentioned All of the mentioned Kitchen?; integer What is the scope of an external variable? Whole source file in which it is From the point of declaration to the Any source file in a program From the point of declaration to From the point of declaration defined end of the file in which it is defined the end of the file being to the end of the file being compiled compiled What is the scope of a function? Whole source file in which it is From the point of declaration to the Any source file in a program From the point of declaration to From the point of declaration defined end of the file in which it is defined the end of the file being to the end of the file being compiled compiled The format identifier ‘%i’ is also used for _____ data type. Char Int Float Double Int Which data type is most suitable for storing a number 65000 in a 32-bit system? Signed short Unsigned short Long Int Signed short Which of the following is a User-defined data type? Typedef int boolean; Typedef enum {mon, tue, wed, thu, Struct {char name, int age}; All of the mentioned All of the mentioned fri} workdays; What is the size of an int data type? 4 bytes 8 bytes Depends on the system/compiler Cannot be determined Depends on the system/compiler What is short int in C programming? The basic data type of c Qualifier Short is the qualifier and int is All of the mentioned Short is the qualifier and int is the basic data type the basic data type Which among the following is the odd one out? Printf Fprintf Putchar Scanf Scanf For a typical program, the input is taken using _________ Scanf Files Command-line All of the mentioned All of the mentioned What does the following command line signify? prog1|prog2 It runs prog1 first, prog2 second It runs prog2 first, prog1 second It runs both the programs, pipes It runs both the programs, pipes It runs both the programs, output of prog1 to input of prog2 output of prog2 to input of pipes output of prog1 to prog1 input of prog2 What is the default return-type of getchar()? Char Int Char * Reading character doesn’t Int require a return-type What is the use of getchar()? The next input character each time it Eof when it encounters end of file The next input character each None of the mentioned The next input character each is called time it is called eof when it time it is called encounters end of file Which of the following statement is true? The symbolic constant eof is defined The value is -1 The symbolic constant eof is Only value is -1 The symbolic constant eof is in defined in & value is -1 defined in What is the return value of putchar()? The character written Eof if an error occurs Nothing Both character written & eof if Eof if an error occurs an error occurs The syntax to print a % using printf statement can be done by ________ % \% ‘%’ %% % What is the precedence of arithmetic operators (from highest to lowest)? %, *, /, +, – %, +, /, *, – #ERROR! %, +, -, *, / %, *, /, +, – Which of the following is not an arithmetic operation? A * = 10; A / = 10; A ! = 10; A % = 10; A ! = 10; Which of the following data type will throw an error on modulus operation(%)? Char Short Int Float Float Are logical operator sequence points? TRUE FALSE Depends on the compiler Depends on the standard TRUE Do logical operators in the C language are evaluated with the short circuit? TRUE FALSE Depends on the compiler Depends on the compiler TRUE What is C++? C++ is an object oriented C++ is a procedural programming C++ supports both procedural C++ is a functional programming C++ supports both procedural programming language language and object oriented language and object oriented programming language programming language Which of the following is the correct syntax of including a user defined header files in #include #include “userdefined” #include #include #include “userdefined” C++? Which of the following is used for comments in C++? // comment */ // comment Both // comment or */ Which of the following extension is used for user-defined header file in c++? Hg Cpp h Hf h Which of the following is a correct identifier in C++? Var_1234 $var_name 7varname 7var_name Var_1234 Which of the following is not a type of Constructor in C++? Default constructor Parameterized constructor Copy constructor Friend constructor Friend constructor Which of the following approach is used by C++? Left-right Right-left Bottom-up Top-down Bottom-up What is virtual inheritance in C++? C++ technique to enhance multiple C++ technique to ensure that a C++ technique to avoid multiple C++ technique to avoid multiple C++ technique to avoid inheritance private member of the base class inheritances of classes copies of the base class into multiple copies of the base can be accessed somehow children/derived class class into children/derived class Which of the following is correct about this pointer in C++? This pointer is passed as a hidden This pointer is passed as a hidden This pointer is passed as a hidden This pointer is passed as a This pointer is passed as a argument in all static variables of a argument in all the functions of a argument in all non-static hidden argument in all static hidden argument in all non- class class functions of a class functions of a class static functions of a class Which of the following type is provided by C++ but not C? Double Float Int Bool Bool By default, all the files in C++ are opened in _________ mode. Binary Vtc Text Iscii Text Which of the following correctly declares an array in C++? Array{10}; Array array; Int array; Int array; Int array; What is the size of wchar_t in C++? Based on the number of bits in the 2 or 4 4 2 Based on the number of bits system in the system What is the use of the indentation in c++? R distinguishes between comments Distinguishes between comments Distinguishes between R distinguishes between Distinguishes between and inner data and outer data comments and code comments and outer data comments and code Which is more effective while calling the C++ functions? Call by object Call by pointer Call by value Call by reference Call by reference Which of the following is used to terminate the function declaration in C++? ; ] ) : ; Which keyword is used to define the macros in c++? #macro #define Macro Define #define The C++ code which causes abnormal termination/behaviour of a program should be Catch Throw Try Finally Try written under _________ block. What is Inheritance in C++? Deriving new classes from existing Overloading of classes Classes with same names Wrapping of data into a single Deriving new classes from classes class existing classes Which of the following symbol is used to declare the preprocessor directives in C++? $ ^ # * # What is meant by a polymorphism in C++? Class having only single form Class having four forms Class having many forms Class having two forms Class having many forms Pick the incorrect statement about inline functions in C++? Saves overhead of a return call from a They are generally very large and These functions are These functions are They are generally very large function complicated function inserted/substituted at the point inserted/substituted at the point and complicated function of call of call What is abstract class in C++? Any class in c++ is an abstract class Class from which any class is derived Class specifically used as a base Class specifically used as a base Class specifically used as a class with atleast one virtual class with atleast one virtual base class with atleast one functions functions virtual functions Which of the following constructors are provided by the C++ compiler if not defined in Copy constructor Copy constructor Assignment constructor All of the mentioned All of the mentioned a class? Which concept allows you to reuse the written code in C++? Inheritance Polymorphism Abstraction Encapsulation Inheritance How structures and classes in C++ differ? Structures by default hide every In structures, members are public by Structures cannot have private In structures, members are In structures, members are member whereas classes do not default whereas, in classes, they are members whereas classes can private by default whereas, in public by default whereas, in private by default have classes, they are public by classes, they are private by default default What is the benefit of c++ input and output over c input and output? Both type safety & exception Sequence container Exception Type safety Type safety What happens if the following line is executed in C and C++? const int a; Error in both c and c++ Warning in both c and c++ Error in c and successful Error in c++ and successful Error in c++ and successful execution in c++ execution in c execution in c Which of the following feature is not provided by C? Pointers Structures References Functions References Which of the following is C++ equivalent for scanf()? Cin Cout Print Input Cin Which of the following is C++ equivalent for printf()? Cin Cout Print Input Cout Which of the following is the correct difference between cin and scanf()? Both are the same Cin is a stream object whereas Scanf() is a stream object Cin is used for printing whereas Cin is a stream object scanf() is a function whereas cin is a function scanf() is used for reading input whereas scanf() is a function Which of the following is an exit-controlled loop? For While Do-while All of the mentioned While Which of the following is an entry-controlled loop? For While Do-while All of the mentioned All of the mentioned In which part of the for loop termination condition is checked? for(I;II;III) {IV} I Ii Ii Iv I What is dynamic binding? The process of linking the actual code The process of linking the actual The process of linking the actual All of the mentioned The process of linking the with a procedural call during run-time code with a procedural call during code with a procedural call at any- actual code with a procedural compile-time time call during run-time What is static binding? The process of linking the actual code The process of linking the actual The process of linking the actual All of the mentioned The process of linking the with a procedural call during run-time code with a procedural call during code with a procedural call at any- actual code with a procedural compile-time time call during compile-time What is name mangling in C++? The process of adding more The process of making common The process of changing the The process of declaring The process of adding more information to a function name so names for all the function of c++ names of variable variables of different types information to a function that it can be distinguished from program for better use name so that it can be other functions by the compiler distinguished from other functions by the compiler Which of the following syntax for declaring a variable of struct STRUCT can be used in Struct struct s; Struct s; Both struct struct s; and struct s; Both c and c++ have different Struct struct s; both C and C++? syntax Which of the following is the scope resolution operator?. * :: ~ :: Which of the following operator has left to right associativity? Unary operator Logical not Array element access Addressof Array element access Which of the following is accessed by a member function of a class? The object of that class All members of a class The public part of a class The private part of a class All members of a class What is the size of a character literal in C and C++? 4 and 1 1 and 4 1 and 1 4 and 4 1 and 1 Which of the following is correct? Struct tag is required in both c and Struct is not required in c but Struct is not required in c++ but Struct tag is not required in both Struct is not required in c++ c++ while declaring an object of the required in c++ while declaring an required in c while declaring an c and c++ while declaring an but required in c while structure object of the structure object of the structure object of the structure declaring an object of the structure Which of the following is correct? Struct cannot have member function Struct cannot have member Struct cannot have member Struct can have member Struct cannot have member in c but it can in c++ function in c++ but it can in c function in both c and c++ function in both c and c++ function in c but it can in c++ Which of the following statement is correct? Structure in c allows constructor Structure in c++ allows constructor Structure in c++ allows C allows constructor definition Structure in c++ allows definition definition constructor definition while c++ does not constructor definition Which of the following is correct about this pointer in C++? This pointer is passed as a hidden This pointer is passed as a hidden This pointer is passed as a hidden This pointer is passed as a This pointer is passed as a argument in all the functions of a argument in all non-static functions argument in all static functions of hidden argument in all static hidden argument in all static class of a class a class variables of a class functions of a class Which of the following operator is used with this pointer to access members of a class?. ! Pointer(->) ~ Pointer(->) Why this pointer is used? To access the members of a class To access all the data stored under To access objects of other class To access objects of other To access the members of a which have the same name as local that class variables class which have the same variables in that scope name as local variables in that scope How many types of polymorphism are there? 1 2 3 4 2 What will be the output of the following C code? #include int main() { int y = 10000; int Compile time error Hello world! 34 Hello world! 1000 Hello world! followed by a junk Compile time error y = 34; printf("Hello World! %d\n", y); return 0; } value What will happen if the following C code is executed? #include int main() { int main = 3; It will cause a compile-time error It will cause a run-time error It will run without any error and It will experience infinite looping It will run without any error printf("%d", main); return 0; } prints 3 and prints 3 What will be the output of the following C code? #include int main() { signed char chr; 128 -128 Depends on the compiler None of the mentioned 128 chr = 128; printf("%d\n", chr); return 0; } What will be the output of the following C code on a 64 bit machine? #include union Sti 8 5 9 4 4 { int nu; char m; }; int main() { union Sti s; printf("%d", sizeof(s)); return 0; } What will be the output of the following C function? #include enum birds {SPARROW, 1 Compile time error 8 7 8 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; } What will be the output of the following C code? #include int const print() { Error because function name cannot Sanfoundry.com Sanfoundry.com is printed Blank screen, no output Sanfoundry.com printf("Sanfoundry.com"); return 0; } void main() { print(); } be preceded by const infinite times Will the following C code compile without any error? #include int main() { for (int k = 0; Yes No Depends on the c standard Error Depends on the c standard k < 10; k++); return 0; } implemented by compilers implemented by compilers What will be the final value of x in the following C code? #include void main() { int x = 5 3.75 Depends on compiler 24 3 24 * 9 / 3 + 9; } What will be the output of the following C code? (Initial values: x= 7, y = 8) #include 7.0000,7 Run time error 7.00000, junk Varies 7.00000, junk void main() { float x; int y; printf("enter two numbers \n"); scanf("%f %f", &x, &y); printf("%f, %d", x, y); } What will be the output of the following C code considering the size of a short int is 2, 2,1,2 2,1,1 2,1,4 2,2,8 2,1,4 char is 1 and int is 4 bytes? #include int main() { short int i = 20; char c = 97; printf("%d, %d, %d\n", sizeof(i), sizeof(c), sizeof(c + i)); return 0; } What is the difference between the following 2 C codes? #include //Program 1 int No difference as space doesn’t make Space does make a difference, Program 1 has syntax error, Program 1 has syntax error, Program 1 has syntax error, main() { int d, a = 1, b = 2; d = a++ + ++b; printf("%d %d %d", d, a, b); } #include any difference, values of a, b, d are values of a, b, d are different program 2 is not program 2 is not program 2 is not //Program 2 int main() { int d, a = 1, b = 2; d = a++ +++b; printf("%d %d %d", d, a, b); } same in both the case What will be the output of the following C code snippet? #include void main() { 1 < 2 ? Returns 1 Returns 2 Varies Compile time error Compile time error return 1: return 2; } What will be the value of the following assignment expression? (x = foo())!= 1 2 TRUE 1 0 1 considering foo() returns 2 What will be the output of the following C function? #include void reverse(int i); int 12345 Segmentation fault Compilation error Undefined behaviour 12345 main() { reverse(1); } void reverse(int i) { if (i > 5) return ; printf("%d ", i); return reverse((i++, i)); } What will be the final values of i and j in the following C code? #include int x = 0; int f() I value is 1 and j value is 1 I value is 0 and j value is 0 I value is 1 and j value is I and j value are undefined I value is 1 and j value is { if (x == 0) return x + 1; else return x - 1; } int g() { return x++; } int main() { int i = (f() + undefined undefined g()) | g(); //bitwise or int j = g() | (f() + g()); //bitwise or } Comment on the following C statement. n = 1; printf("%d, %dn", 3*n, n++); Output will be 3, 2 Output will be 3, 1 Output will be 6, 1 Output is compiler dependent Output is compiler dependent How many times i value is checked in the following C program? #include int main() { int 2 3 4 1 4 i = 0; while (i < 3) i++; printf("In while loop\n"); } What will be the output of the following C code? #include int main() { int i = 0; do { i++; In while loop 2 In while loop in while loop 3 In while loop 3 Infinite loop In while loop 2 if (i == 2) continue; printf("In while loop "); } while (i < 2); printf("%d\n", i); } What will be the data type returned for the following C function? #include int func() { Char Int Double Multiple type-casting in return is Int return (double)(char)5.0; } illegal What is the problem in the following C declarations? int func(int); double func(int); int A function with same name cannot A function with same name cannot A function with same name All of the mentioned All of the mentioned func(float); have different signatures have different return types cannot have different number of parameters Which option should be selected to work the following C expression? string p = Typedef char string; Typedef char *string; Typedef char string; and typedef Such expression cannot be Typedef char *string; "HELLO"; char *string; generated in c What is the meaning of the following C statement? printf(“%10s”, state); 10 spaces before the string state is 10 spaces before the string state is Print the last 10 characters of the None of the mentioned 10 spaces before the string printed printed string state is printed What are the elements present in the array of the following C code? int array = {5}; 5, 5, 5, 5, 5 5, 0, 0, 0, 0 5, (garbage), (garbage), (garbage), (garbage), (garbage), 5, 0, 0, 0, 0 (garbage), (garbage) (garbage), 5 Which part of the program address space is p stored in the following C code? #include Code/text segment Data segment Bss segment Stack Bss segment int *p; int main() { int i = 0; p = &i; return 0; } Which of the following sequences are unaccepted in C language? #if #else #endif #if #elif #endif #if #if #endif #if #undef #endif #if #if #endif Comment on the output of following C code. #include main() { char *p = 0; *p = 'a'; It will print a It will print 0 Compile time error Run time error Run time error printf("value in pointer p is %c\n", *p); } What is the output of this C code? #include main() { char *p = "Sanfoundry C-Test"; p = Abnfoundry c-test Sanfoundry c-test Compile time error Run time error Run time error 'a'; p = 'b'; printf("%s", p); } What is the output of this C code? #include int main() { float f = 0.1; if (f == 0.1) TRUE FALSE No output will be printed compilation error FALSE printf("True"); else printf("False"); } What is the output of this C code? #include main() { int n = 0, m = 0; if (n > 0) if (m > 0) TRUE FALSE No output will be printed Run time error No output will be printed printf("True"); else printf("False"); } What will be output of the following C code where we copy an array ‘a’ into array ‘b’ Hello, hello Hell, hell Hell, hello Runtime error Hell, hell and then the array ‘b’ into ‘a’? #include #include main() { char a = "hell"; char b = "hello"; strcpy(b, a); strcpy(a, b); printf("%s, %s", a, b); } What will be the output of the following C code? #include void main() { int a = {1, 2, 3, 123450 1 2 3 4 5 junk 123455 Run time error 123450 4, 5}; int i = 0, j = 0; for (i = 0; i < 2; i++) for (j = 0; j < 3; j++) printf("%d", a); } What will be the output of the following C code? #include void f(int a) { a = 3; int i = 0, j 0 3 0 0 0 0 Junk 3 junk junk junk junk Compile time error All junk values 030000 = 0; for (i = 0; i < 2; i++) for (j = 0; j < 3; j++) printf("%d", a); } void main() { int a = {0}; f(a); } Comment on the following 2 arrays with respect to P and Q. int *a1; int *(a2); P. Array A1 is p, a2 is q A1 is p, a2 is p A1 is q, a2 is p A1 is q, a2 is q A1 is p, a2 is p of pointers Q. Pointer to an array What will be the output of the following C code? #include void foo(int (*ary)); int Compile time error 10 2 Undefined behaviour Segmentation fault/code crash Compile time error main() { int ary; foo(ary); } void foo(int (*ary)) { int i = 10, j = 2, k; ary = &i; ary = &j; for (k = 0;k < 2; k++) printf("%d\n", *ary); } What will be the output of the following C code? #include int main() { int a = {1, 2, 3, 4, The compiler will flag an error The program will compile and print The program will compile and The program will compile and The program will compile and 5}; int i; for (i = 0; i < 5; i++) if ((char)a == '5') printf("%d\n", a); else printf("FAIL\n"); } the output 5 print the ascii value of 5 print fail for 5 times print fail for 5 times What will be the output of the following C code? #include int main() { signed char chr; 128 -128 Depends on the compiler None of the mentioned 128 chr = 128; printf("%d\n", chr); return 0; } What will be the output of the following C code? #include int main() { char c; int i = 0; a Infinite loop Depends on what fgetc returns Depends on the compiler a 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; } What will be the output of the following C code? #include int main() { float f1 = 0.1; if Equal Not equal Output depends on the compiler Error Equal (f1 == 0.1) printf("equal\n"); else printf("not equal\n"); } What will be the output of the following C code on a 32-bit machine? #include int P and q are 4 and 4 P and q are 4 and 8 Compiler error P and q are 2 and 8 P and q are 4 and 4 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; } What will be the output of the following C code on a 64 bit machine? #include union Sti 8 5 9 4 4 { int nu; char m; }; int main() { union Sti s; printf("%d", sizeof(s)); return 0; } What will be the output of the following C code? #include int main() { float x = 'a'; a Run time error A.00000000 97 97 printf("%f", x); return 0; } What will be the output of the following C code? const char pla = "string1"; const char Before memmove place= string1, src Before memmove place = string2, Before memmove place = Before memmove place= string1, Before memmove place= src = "string2"; printf("Before memmove place= %s, src = %s\n", pla, src); = string2 after memmove place = src = string2 after memmove place= string2, src = string1 after src = string2 after memmove string1, src = string2 after memmove(pla, src, 7); printf("After memmove place = %s, src = %s\n", pla, src); string2, src = string2 string1, src = string2 memmove place= string2, src place=string1, src = string1 memmove place = string2, src =string2 = string2 What will be the output of the following C code? const char str1="ABCDEF1234567"; First matching character is at 8 First matching character is at 7 First matching character is at 9 First matching character is at 12 First matching character is at const char str2 = "269"; len = strcspn(str1, str2); printf("First matching character is at 8 %d\n", len + 1); What will be the output of the following C code? const char str1 = "abcdef"; const char g a h f a str2 = "fgha"; char *mat; mat= strpbrk(str1, str2); if(mat) printf("First matching character: %c\n", *mat); else printf("Character not found"); What will be the output of the following C code? char str1 = "Helloworld "; char str2 = 6 5 4 No match 5 "Hello"; len = strspn(str1, str2); printf("Length of initial segment matching %d\n", len ); What will be the output of the following C code? #include int main() { int a = 1, b = 2, c 7, 4 7, 2 5, 2 Syntax error Syntax error = 3, d = 4, e; e = c + d = b * a; printf("%d, %d\n", e, d); } What will be the output of the following C code? #include int main() { int x = 2, y = 2; 2 4.000000 Compile time error 2 3.500000 Undefined behaviour Compile time error float f = y + x /= x / y; printf("%d %f\n", x, f); return 0; } What will be the output of the following C code? #include int main() { int x = 1, y = 2; int 1 Compile time error Undefined behaviour 1 z = x & y == 2; printf("%d\n", z); } What will be the output of the following C code? #include int main() { int x = 3, y = 2; int 1 Compile time error Floating point exception Segmentation fault/code crash Floating point exception z = x /= y %= 2; printf("%d\n", z); } What happens if the following C++ statement is compiled and executed? int *ptr = The program is not semantically The program is compiled and The program gives a compile- The program compiled The program is compiled and NULL; delete ptr; correct executed successfully time error successfully but throws an error executed successfully during run-time What will be the output of the following C++ code? #include #include using namespace Hello World Error Hello world Error std; int main(int argc, char const *argv) { char s1 = "Hello"; char s2 = "World"; char s3 = s1 + " " + s2; cout< What happens if the following program is executed in C and C++? #include int Error in c and successful execution in Error in both c and c++ Error in c++ and successful A successful run in both c and Error in c++ and successful main(void) { int new = 5; printf("%d", new); } c++ execution in c c++ execution in c What happens if the following program is executed in C and C++? #include void Outputs hello twice in both c and c++ Error in c and successful execution Error in c++ and successful Error in both c and c++ Error in both c and c++ func(void) { printf("Hello"); } void main() { func(); func(2); } in c++ execution in c What will be the output of the following C++ code? #include #include #include using Spacesintext Spaces in text Spaces Spaces in Spacesintext namespace std; int main() { string s = "spaces in text"; s.erase(remove(s.begin(), s.end(), ' ' ), s.end() ) ; cout

Use Quizgecko on...
Browser
Browser