Sunday, December 31, 2023

C Branching Statements MCQs with Answer - Set 2

C - Branching Statements MCQs Set 2


Followings are 10 important C programming MCQs on branching statements, along with their answers:

1. Which of the following is not a branching statement in C?
a) if 
b) switch 
c) while 
d) goto

Answer: c) while (while is a looping statement, not a branching statement)

2. What is the output of the following code?

int x = 10;
if (x > 5) {
  printf("x is greater than 5");
} else {
  printf("x is less than or equal to 5");
}

a) x is greater than 5 
b) x is less than or equal to 5 
c) Compile error 
d) Runtime error

Answer: a) x is greater than 5

3. Which of the following is a multiway decision statement in C?
a) if 
b) switch 
c) for 
d) while

Answer: b) switch

4. Is the default case compulsory in the switch case statement?
a) Yes 
b) No 
c) Depends on the compiler
d) None of the above

Answer: b) No

5. What happens when a break statement is encountered in a switch case?
a) The program terminates
b) The switch statement terminates 
c) The current loop terminates
d) None of the above

Answer: b) The switch statement terminates

6. If the Boolean expression of an if statement evaluates to true, then which block of code is executed?
a) The block inside the if statement 
b) The block inside the else statement 
c) Both blocks 
d) None of the blocks

Answer: a) The block inside the if statement

7. Can a switch statement have multiple case labels with the same value?
a) Yes 
b) No 
c) Depends on the compiler 
d) None of the above

Answer: a) Yes

8. What is the output of the following code?

int num = 4;
switch (num + 2) {
  case 4: printf("4"); break;
  case 3: printf("3"); break;
  case 6: printf("6"); break;
}

a) 4 
b) 3 
c) 6 
d) Compile error

Answer: c) 6

9. Can a break statement be used inside an if statement?
a) Yes 
b) No 
c) Depends on the compiler 
d) None of the above

Answer: b) No

10. What is the purpose of the default case in a switch statement?
a) To handle all cases that are not explicitly handled by other cases 
b) To terminate the switch statement
c) To cause a compile error 
d) None of the above

Answer: a) To handle all cases that are not explicitly handled by other cases

< HOME

Saturday, December 30, 2023

Top 10 C Programming Libraries

Top 10 C Programming Libraries

Ranking C libraries can be very subjective, and dependent on your own usage. However, here are 10 C libraries that are widely used across various domains:

1. Standard C Library (libc):

  • Foundational library included with every C compiler.
  • Provides essential functions for input/output, memory management, string manipulation, math operations, and more.
  • Basis for most C programming.

2. GLib:

  • General-purpose utility library used in many C projects, including GNOME desktop applications.
  • Offers data structures, functions for string handling, networking, file I/O, threading, and more.
  • Cross-platform and supports various programming paradigms.

3. OpenSSL:

  • Toolkit for implementing secure communication protocols like TLS and SSL.
  • Provides cryptographic functions for encryption, decryption, authentication, and certificate management.
  • Essential for building secure network applications.

4. libcurl:

  • Client-side URL transfer library for fetching data from web servers.
  • Supports various protocols (HTTP, HTTPS, FTP, etc.), authentication methods, and proxy settings.
  • Widely used in web applications and command-line tools.

5. libpng:

  • Reference library for reading and writing PNG image files.
  • Handles PNG compression, decompression, color management, and metadata.
  • Widely used for working with PNG images in C programs.

6. libjpeg:

  • Library for handling JPEG image files, similar to libpng for PNG.
  • Compresses and decompresses JPEG images, supports various color spaces and features.
  • Essential for working with JPEG images in C.

7. zlib:

  • General-purpose data compression library, often used with other libraries.
  • Implements the DEFLATE compression algorithm, commonly used in PNG, gzip, and other formats.
  • Reduces file sizes and network transfer times.

8. SQLite:

  • Embedded SQL database engine, allowing C programs to store and manage data without an external database server.
  • Self-contained, serverless, and lightweight, making it suitable for embedded systems and mobile apps.

9. SDL (Simple DirectMedia Layer):

  • Cross-platform library for multimedia programming, handling input, audio, graphics, and more.
  • Widely used for developing games, emulators, and media applications in C.

10. OpenGL:

  • Graphics API for rendering 2D and 3D graphics, often used with SDL for cross-platform compatibility.
  • Provides hardware-accelerated rendering for high-performance graphics applications.