1. Home
  2. All MCQs

All MCQs with Answers · Page 1489

45,334 multiple choice questions from every subject, newest first. Switch on practice mode to hide the answers and test yourself.

Newest first

Inside two nested for loops, a break statement in the body of the inner loop terminates what?

  1. Only the innermost loop that lexically encloses the break Correct answer
  2. Both loops, since break always leaves the outermost loop
  3. The entire function, returning control to the caller
  4. The current iteration of both loops, then continues with the next outer iteration
MCQSEXAM Read explanation

A qsort comparator for int returns (a - b) and is used on values close to INT_MIN and INT_MAX. Why is this a defect?

  1. The comparator must return only 0 or 1, and any other return value is ignored by the qsort implementation
  2. Signed overflow in the subtraction is undefined behaviour, so the sign of the result can be wrong Correct answer
  3. qsort requires the comparator to return a long rather than an int, so the subtraction must be widened
  4. qsort calls the comparator once per element, so ties between equal keys are never detected at all
MCQSEXAM Read explanation

A buffer is grown with p = realloc(p, 2 * n); and the call fails. What is the correct statement?

  1. The original block is automatically freed before the call returns, so p is left as a null pointer
  2. The original block is truncated to half its size before the failure, so the buffer keeps only its data
  3. realloc cannot fail when the new size is larger than the old one, because growth always happens in place
  4. The original block is untouched and still allocated, so assigning the result directly to p leaks it Correct answer
MCQSEXAM Read explanation

int a[3] = {10, 20, 30}; int *p = a; int x = *p++; what are x and the new value of *p?

  1. x is 11, because the increment applies to the pointed-to int rather than to the pointer itself
  2. x is 10 and *p is now 20, because postfix ++ binds tighter than * and yields the old pointer value Correct answer
  3. x is 10 and p still points at a[0], because the unary * is evaluated before the postfix increment
  4. x is 20, because the pointer is incremented before it is dereferenced and the old value is discarded
MCQSEXAM Read explanation

In C (not C++), what is the status of storing a value in one union member and then reading a different member of the same size?

  1. Undefined behaviour in C as well, exactly as it is in C++, so the compiler may assume it never happens
  2. A constraint violation, so a conforming compiler must reject the program instead of silently reinterpreting it
  3. Permitted; the bytes are reinterpreted and the result is implementation-defined, which is called type punning Correct answer
  4. A conversion that applies the usual arithmetic conversions to the stored bytes before reading them back
MCQSEXAM Read explanation

What does the C standard guarantee about the return value of malloc(0)?

  1. Always a null pointer, because zero bytes can never be allocated by any conforming malloc
  2. Always a valid pointer to exactly one byte, because malloc rounds every request up to one byte
  3. Undefined behaviour, so the program is invalid whatever pointer the call happens to return
  4. A null pointer or a unique pointer that can be passed to free are both conforming outcomes Correct answer
MCQSEXAM Read explanation

char *p = "hello"; p[0] = 'H'; is executed. What is the status of this program under the C standard?

  1. Undefined behaviour, because the string literal has static storage and must not be modified Correct answer
  2. It is well defined, but only on little-endian machines and only when the optimisation is disabled
  3. It works as intended, because p is a non-const pointer that points at a writable array
  4. It is a syntax error, because string literals cannot be indexed or assigned through any pointer
MCQSEXAM Read explanation

For int n = -1; size_t sz = 4; what is the value of (n < sz) in C, and why?

  1. True, because size_t is promoted to int before the comparison under the usual arithmetic conversions in C here
  2. A compile-time error, since signed and unsigned operands may never be compared without an explicit cast
  3. False, because n is converted to size_t in the usual arithmetic conversions and becomes a very large value Correct answer
  4. True, because -1 is promoted to int and then compared as an ordinary signed value in this expression
MCQSEXAM Read explanation

Consider void f(int a[10]) { printf("%zu", sizeof a); } called with an int arr[10] on a 64-bit LP64 platform. What does the sizeof expression print?

  1. 8, because the parameter is adjusted to int * and sizeof then measures a pointer Correct answer
  2. 40, because the declared bound of 10 ints is part of the parameter type
  3. 4, because the array name always decays to a single int
  4. 80, because the decayed pointer is doubled for bounds checking
MCQSEXAM Read explanation

Which statement about electroconvulsive therapy in contemporary practice is correct?

  1. It is a first-line treatment for mild depression and is given as an outpatient without anaesthesia or muscle relaxation
  2. It invariably causes permanent memory loss and is therefore reserved for elderly patients only
  3. It is used for severe depression with psychosis or food refusal and is given under anaesthesia with muscle relaxation Correct answer
  4. It is absolutely contraindicated during pregnancy and in patients with a history of epilepsy
MCQSEXAM Read explanation

A depressed patient says that everyone would be better off without him. What is the most appropriate nursing response?

  1. Tell him not to talk that way and distract him with ward activities and television
  2. Record the statement in the notes and continue with the routine observation round
  3. Reassure him that he is valued and change the subject to something pleasant
  4. Ask directly whether he has thoughts of harming himself and whether he has a plan Correct answer
MCQSEXAM Read explanation

A patient taking lithium for bipolar disorder presents with coarse tremor, vomiting, ataxia and confusion, and the serum lithium is 2.5 mmol/L. What is the priority action?

  1. Add a thiazide diuretic to increase renal excretion of lithium
  2. Reassure the patient and continue the same dose with more frequent level checks
  3. Withhold lithium and arrange urgent supportive care with dialysis if severe Correct answer
  4. Increase the dose to control emerging mania while monitoring the level
MCQSEXAM Read explanation

A patient taking haloperidol develops lead-pipe rigidity, a temperature of 40 degrees Celsius, confusion and a creatine kinase of 5,000 U/L. What is the diagnosis and immediate action?

  1. Neuroleptic malignant syndrome; stop the antipsychotic and give bromocriptine or dantrolene Correct answer
  2. Serotonin syndrome; give cyproheptadine, stop serotonergic drugs and cool the patient actively
  3. Acute dystonia; give benztropine and continue the antipsychotic at a lower dose
  4. Tardive dyskinesia; reduce the dose and switch to a second-generation antipsychotic
MCQSEXAM Read explanation

A toddler with tetralogy of Fallot becomes deeply cyanotic while crying and squats. Why does squatting relieve the cyanosis?

  1. It raises systemic vascular resistance, reducing the right-to-left shunt Correct answer
  2. It increases the oxygen carrying capacity of blood by splenic contraction
  3. It slows the heart rate and increases coronary perfusion to the right ventricle
  4. It reduces venous return to the right ventricle and lowers its output
MCQSEXAM Read explanation

A term newborn is visibly jaundiced at six hours of age with a total bilirubin of 12 mg/dL. How should this be interpreted?

  1. Pathological jaundice requiring urgent investigation for haemolysis or sepsis Correct answer
  2. Breast milk jaundice appearing in the first week and resolving without treatment
  3. Normal variation needing no action and no further bilirubin measurement
  4. Physiological jaundice that can be observed and rechecked at 48 hours of age
MCQSEXAM Read explanation