C Programming and Problem Solving Questions and Answers 141 to 150

C Programming and Problem Solving

Questions 141 to 150



141.
char *ptr;
char myString[] = “abcdefg”;
ptr = myString;
ptr += 5;
what string does ptr point to in the sample code above?
(a)
fg
(b)
efg
(c)
defg
(d)
cdefg
(e)
bcdefg.
142.
Which one of the following will declare a pointer to an integer at address 0x200 in memory?
(a)
int *x;
*x = 0x200;
(b)
int *x = &0x200;
(c)
int *x = *0x200;
(d)
int *x = 0x200;
(e)
int *x(&0x200);.
143.
x = 3, counter = 0;
while ((x-1))
{
   ++counter;
   x--;
}
Referring to the sample code above, what value will the variable counter have when completed?
(a)
0
(b)
1
(c)
2
(d)
3
(e)
4.
144.
What is the result of the following code?
x=0;
switch(x)
{
  case 1: cout<<"One";
  case 0: cout<<"Zero";
  case 2: cout<<"Hello World";
}
(a)
ZeroHello World
(b)
Zero
(c)
Hello World
(d)
One
(e)
OneHello World.
145.
short testarray[4][3] = { {1}, {2,3}, {4,5,6}};
printf(“%d\n”, sizeof(testarray));
Assuming a short is two bytes long, what will be printed by the above code?
(a)
It will not compile because not enough initializers  are given
(b)
6
(c)
7
(d)
12
(e)
24.
146.
Which one of the following will read a character from the keyboard and will store it in the variable c?
(a)
c = getc()
(b)
getc(&c)
(c)
c = getchar(stdin)
(d)
getchar(&c)
(e)
c = getchar().
147.
What does the “auto” specifier do?
(a)
It automatically initializes a variable to 0

(b)
It indicates that a variable’s memory will automatically be preserved
(c)
It automatically increments the variable when used
(d)
It automatically initializes a variable to NULL
(e)
It indicates that a variable’s memory space is allocated upon entry into the block.
148.
How is a variable accessed from another file?
(a)
The global variable is referenced via the extern specifier
(b)
The global variable is referenced via the auto specifier
(c)
The global variable is referenced via the global specifier
(d)
The global variable is referenced via the pointer specifier
(e)
The global variable is referenced via the ext specifier.
149.
Which one of the following is valid for opening a read-only ASCII file?
(a)
fileOpen(filename, “r”);
(b)
fopen(filename, “ra”);
(c)
fileOpne(filename, read);
(d)
fopen(filename, “read”);
(e)
fopen(filename, “r”);.
150.
What is the meaning of self-referential structure?
(a)
Array of structure
(b)
Single structure
(c)
Structure calling it’s parent structure
(d)
Structure calling another structure
(e)
List of structure.

Answers

141.
Answer : (a)
Reason:  The code is executed the output of the program is fg. Hence the answer is a
142.
Answer : (a)
Reason:  int *x; *x=0x200 is the correct declaration of a pointer to an integer at address 0x200 in memory
143.
Answer : (c)
Reason:  the answer for the code is 2. hence the choice is c
144.
Answer : (a)
Reason:  the initial value of  x is 0. so first case 0 will be executed , there is no break after the case 0 so next case 2 will be executed . Hence the answer is a.
145.
Answer : (e)
Reason:  the size of an array testarray is 24
146.
Answer : (e)
Reason:  getchar() is the function it will read a character from the keyboard
147.
Answer : (b)
Reason:  Auto is a automatic storage class. The purpose of auto is it indicates that a variable’s memory  will automatically be preserved
148.
Answer : (a)
Reason:  the global variable is referenced via the extern specifier
149.
Answer : (e)
Reason:  fopen(filename, “r”) is valid for opening a read-only ASCII file
150.
Answer : (c)
Reason:  The meaning of self referential structure is a structure calling it’s parent structure


<< Prev 1...  2...  3...  4...  5...  6...  7...  8...  9...  10...  11... 12...  13...  14...  15...  16...  17...  18...  19...  20...  21...  22...  23...  24...  25...  26...  27...  28...  29...  30...  31...  32...  33...  34...  35...  36...  Next >>


No comments :

What you think about these Questions and Answers ? Let me know in comments.

Post a Comment