Programmers'Day Quizzard
#include<iostream>
using namespace std;
class Empty {};
int main(). { cout << sizeof(Empty);
return 0; }
Answer : Answer : A non-zero
value
Question : 2).
class Test { int x; };
int main() { Test t;
cout << t.x; return 0;
}
Answer : Compiler Error
Question : 3)
Assume that an integer and a pointer
each takes 4 bytes. Also, assume that there is no alignment in objects. Predict
the output following program.
#include<iostream>
using namespace std;
class Test { static int x;
int *ptr; int y;
};
int main() { Test t; cout << sizeof(t)
<< " ";
cout << sizeof(Test *);
}
Answer : No
Question : 4).Which of the following
is true about the following program
#include <iostream>
class Test { public: int i;
void get();
}; void Test::get() {std::cout
<< "Enter the value of i:"; std::cin >> i; Test t; //
Global objectint main() { Test t; // lo
cal object t.get();
std::cout << "value of i
in local t: "<<t.i<<'n'; ::t.get();
std::cout << "value of i
in global t: "<<::t.i<<'n';
return 0; }
Answer : Compiles and runs fine
Question : 5).What is the output of
the following program?
#include<iostream>
using namespace std;
main() { char s[] =
"hello", t[] = "hello";
if(s==t) cout<<"eqaul
strings";
}
Answer : Un Equal strings
Question : 6).What is the output of
the following program?
#include<iostream> using
namespace std;
main() { union abc { int x;
char ch; } var; var.ch = 'A';
cout<<var.x;
}
Answer : Garbage value
Question : 7).What is the output of
the following program?
#include<iostream>
using namespac e std;main() {
char *s = "Fine";
*s = 'N'; cout<<s<<endl;
}
Answer : Runtime Error
Question : 8).What is the output of
the following program?
#include <iostream>
using namespace std;
int main(){
double firstNumber,
secondNumber,
productOfTwoNumbers;
cout << "Enter two numbers: ";
// Stores two floating point numbers
in variable
firstNumber and secondNumber
respectively cin >> firstNumber >> secondNumber; //
Performs multiplication and stores
the result in variable productOfTwoNumbers productOfTwoNumbers = firstNumber *
secondNumber; cout << "Product = " <<
productOfTwoNumbers;
return 0;
}
Answer : 18
Question : 9).What is the output of
the following program?
#include <iostream>
using namespace std;
int main() {
int num, originalNum, remainder,
result = 0;
cout << "Enter a
three-digit integer: ";
cin >> num; originalNum = num;
while (originalNum != 0)
{ // remainder contains the last
digit remainder = originalNum % 10; result += remainder * remainder *
remainder; // removing last digit from the orignal number originalNum /= 10; }
if (result == num) cout << num
<< " is an Armstrong number.";
else cout << num <<
" is not an Armstrong number.";
return 0;
}
Answer : 371
Question : 10).What is the output of
the following program?.
public class AddTwoNumbers {
public static void main(String[]
args) {
int num1 = 5, num2 = 15, sum;
sum = num1 + num2;
System.out.println("Sum of these
numbers: "+sum);
}
}
Answer : 20
Question : 11).What is the output of
the following program?
class HelloWorld { public static void
main(String[] args) {
System.out.println("Hello, World!");
}
}
Answer : Hello, World!
Question : 12).What is the output of
the following program?
class Main { public static void
main(String[] args)
{ int n = 1;
// for loop for (int i = 1; i <= n; ++i) {
System.out.println("Java is
fun");
} }}
Answer : Java is fun
Question : 13).What is the output of
the following program?
#include<stdio.h>
main() { int x = 3; x += 2; x =+ 2;
printf("%d", x); }
Answer : 2
1 Question : 4).In normalized form,
if the binary equivalent of 5.375 is “0100 0000 1010 1100 0000 0000 0000 0000”
then what will be the output of the program in Intel core machine?
Answer : 00 00 AC 40
Question : 15).In the given below
code, the function fopen()uses "r" to open the file “source.txt” in
binary mode for which purpose?
Answer : For reading
No comments:
Post a Comment
if you have any doubt please let me know