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.


Friday, October 13, 2023

Flowchart to check prime number

Prime Number

" a whole number greater than 1 that cannot be exactly divided by any whole number other than itself and 1 (e.g. 2, 3, 5, 7, 11)."

Prime numbers are very useful in cryptography.

Flowchart to check a Prime Number

Following flowchart is prepared using a RAPTOR software.
Prime number Flowchart

Python Logic to check a prime number.

def is_prime(n):
  if n <= 1:
    return False
  for i in range(2, int(n**0.5) + 1):
    if n % i == 0:
      return False
  return True

Output of python program:

is_prime(5)
True



Friday, September 8, 2023

C Operators MCQs Set 2

C Operators MCQs Set 2

Important MCQs based on C Programming Operators. 


1. What does the % operator do in C?

a) Addition

b) Subtraction

c) Multiplication

d) Modulus


2. Which operator is used for logical NOT in C?

a) &

b) &&

c) !

d) ||


3. What is the result of the expression 5 + 3 * 2 in C?

a) 10

b) 16

c) 11

d) 13


4. What is the result of the expression 10 / 3 in C?

a) 3.3333

b) 3

c) 3.0

d) 4


5. Which operator is used to check if two values are equal in C?

a) ==

b) =

c) !=

d) ===


6. What does the ++ operator do when placed before a variable, like ++x?

a) Decrements the variable by 1

b) Multiplies the variable by 2

c) Increments the variable by 1

d) Doubles the value of the variable


7. Which operator is used to access the value stored at a memory address in C?

a) &

b) *

c) ->

d) .


8. What does the += operator do in C?

a) Subtracts the right-hand value from the left-hand value

b) Multiplies the left-hand value by the right-hand value

c) Adds the right-hand value to the left-hand value

d) Divides the left-hand value by the right-hand value


9. Which operator is used to shift the bits of a number to the left in C?

a) >>

b) <<

c) &

d) |


10. What does the ternary conditional operator ? : do in C?

a) It checks if a condition is true and returns 1 if true, 0 if false.

b) It assigns a value to a variable.

c) It performs addition.

d) It provides a shorthand way to write an if-else statement.


Correct Answers:


1. d) Modulus

2. c) !

3. c) 11

4. b) 3

5. a) ==

6. c) Increments the variable by 1

7. b) *

8. c) Adds the right-hand value to the left-hand value

9. b) <<

10 d) It provides a shorthand way to write an if-else statement.


< Back to Question Bank >

< Home >


Monday, June 12, 2023

Top 10 C Programming Topics for Beginners

Followings are the top 10 topics for the C programming beginners. These topics are essential for understanding the C programming language and for writing effective C programs:

Top 10 Topics for C Programming Beginners

  1. Data types
  2. Variables
  3. Input / Output (I/O) Operations
  4. Operators
  5. Control flow statements
  6. Functions
  7. Arrays
  8. Strings
  9. Pointers
  10. File handling

Here is a brief overview of each topic:

  • Data types: Data types are the building blocks of C programs. They define the type of data that can be stored in a variable.
  • Variables: Variables are used to store data. They are given names and can be used to store values of different data types.
  • Input / Output (I/O) Operations: I/O operations are used to manage data input from the user or a File. printf() and scanf() are two popular I/O functions.
  • Operators: Operators are used to perform operations on data. They can be used to perform arithmetic operations, logical operations, and string operations.
  • Control flow statements: Control flow statements are used to control the flow of execution of a C program. They can be used to make decisions, loops, and jumps.
  • Functions: Functions are blocks of code that are reusable. They can be called from other parts of a C program.
  • Arrays: Arrays are variables that can store multiple values of the same data type.
  • Strings: Strings are arrays of characters. They are used to store text data.
  • Pointers: Pointers are variables that store the address of another variable. They can be used to access the value of another variable indirectly.
  • File handling: File handling is used to read and write data to files. It is a powerful tool that can be used to store and retrieve data from files.

These are just a few of the many topics that every C programming beginners should learn. If you are interested in learning C programming, we recommend that you find a good book or online Self Study Tutorials that covers these topics in detail.




Tuesday, April 18, 2023

C Programming Predict Output Strings MCQs Set 3 - Answer

Predict Output MCQs Based On C Programming Strings - Answer

1. What is the output of the following C program?

#include <stdio.h>

int main() {
char str1[] = "hello";
char str2[] = "world";
printf("%s", str1);
printf("%s", str2);
return 0;
}

A) helloworld
B) hello world
C) hello
   world
D) Compilation error

Answer: A) helloworld

Explanation: str1 array contains the string "hello", and str2 contains the string "world". The printf function outputs str1 followed by str2, which results in "helloworld".

2. What is the output of the following C program?

#include <stdio.h>
int main() {
char str[] = "hello";
printf("%c", str[3]);
return 0;
}

A) h
B) e
C) l
D) o

Answer: C) l

Explanation: The str array contains the string "hello". The expression str[3] retrieves the character at index 3 of the array, which is 'l'. Hence program outputs 'l'.

3. What is the output of the following C program?

#include <stdio.h>
int main() {
char str1[] = "hello";
char str2[] = "world";
printf("%s", str1 + 3);
printf("%s", str2 + 1);
return 0;
}
A) loorld
B) loorldw
C) loworld
D) helloworld

Answer: A) loorld

Explanation: The expression str1 + 3 evaluates to a pointer to the fourth character of str1, which is 'l'. The printf function then outputs the remaining characters of str1 starting from the fourth character, which is "lo". Similarly, the expression str2 + 1 evaluates to a pointer to the second character of str2, which is 'o'. The printf function then outputs the remaining characters of str2 starting from the second character, which is "orld". Hence, final output will be "loorld".

4. What is the output of the following C program?

#include <stdio.h>
int main() {
char str[] = "hello";
str[2] = '\0';
printf("%s", str);
return 0;
}
A) hel
B) he
C) hello
D) Compilation error

Answer: B) he

Explanation: The str contains the string "hello". The statement str[2] = '\0' sets the third character of str to the null character, which terminates the string. The printf function then outputs the characters of str up to the null character, which is "he".

5. What is the output of the following C program?

#include <stdio.h>
int main() {
int arr[] = {2, 3, 4};
int *p = arr;
printf("%d", *(p + 1));
return 0;
}
A) 2
B) 3
C) 4
D) Compilation error

Answer: B) 3

Explanation: The pointer p points to the first element of the array arr. The expression *(p + 1) adds 1 to the pointer p to point to the second element of the array, and then evaluates to the value pointed to by the new pointer, which is 3.




C Programming String Predict Output MCQs Set 3

 Predict output MCQs based on C Programming Strings

1. What is the output of the following C program?

#include <stdio.h>

int main() {

   char str1[] = "hello";

   char str2[] = "world";

   printf("%s", str1);

   printf("%s", str2);

   return 0;

}

A) helloworld

B) hello world

C) hello

   world

D) Compilation error


2. What is the output of the following C program?

#include <stdio.h>

int main() {

   char str[] = "hello";

   printf("%c", str[3]);

   return 0;

}

A) h

B) e

C) l

D) o


3. What is the output of the following C program?

#include <stdio.h>

int main() {

   char str1[] = "hello";

   char str2[] = "world";

   printf("%s", str1 + 3);

   printf("%s", str2 + 1);

   return 0;

}

A) loorld

B) loorldw

C) loworld

D) helloworld


4. What is the output of the following C program?

#include <stdio.h>

int main() {

   char str[] = "hello";

   str[2] = '\0';

   printf("%s", str);

   return 0;

}

A) hel

B) he

C) hello

D) Compilation error


5. What is the output of the following C program?

#include <stdio.h>

int main() {

   int arr[] = {2, 3, 4};

   int *p = arr;

   printf("%d", *(p + 1));

   return 0;

}

A) 2

B) 3

C) 4

D) Compilation error


Check ANSEWR here...