0% found this document useful (0 votes)
6 views

C With Linux MCQs

The document contains a series of multiple-choice questions related to C programming and Linux commands, covering topics such as algorithms, file permissions, and system commands. Each question includes the correct answer and a brief explanation. The questions are designed to test knowledge and understanding of programming concepts and Linux operating system functionalities.

Uploaded by

kuna.padmaja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

C With Linux MCQs

The document contains a series of multiple-choice questions related to C programming and Linux commands, covering topics such as algorithms, file permissions, and system commands. Each question includes the correct answer and a brief explanation. The questions are designed to test knowledge and understanding of programming concepts and Linux operating system functionalities.

Uploaded by

kuna.padmaja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

C Programming with Linux - I

Practice Questions (MCQs)

Module - I

Sl Question

1
What does the term "algorithm" refer to?
A) A graphical representation of a process
B) A step-by-step procedure to solve a problem
C) A programming language
D) An operating system

Solution: (B)
Explanation: An algorithm is a well-defined, step-by-step sequence of instructions to solve a
problem or accomplish a task.

2
Which symbol is commonly used in flowcharts to represent a decision?
A) Rectangle
B) Oval
C) Diamond
D) Parallelogram

Solution: (C)
Explanation: A diamond shape in a flowchart represents a decision-making process, typically
involving "Yes" or "No" outcomes.

3
In pseudocode, what does the keyword "IF" typically represent?
A) Loop initialization
B) Conditional statement
C) Input statement
D) Output statement

Solution: (B)
Explanation: "IF" is used in pseudocode to indicate a conditional statement that executes a
specific block of code if the condition is true.

4
Which of the following is the root directory in the Linux file system?

A) /root
B) /home
C) /
D) /bin

Solution: (C)
Explanation: / is the root directory in the Linux file system, serving as the starting point for all
other directories.

5
What is an absolute path?
A) A path starting from the current working directory
B) A path that starts from the root directory /
C) A relative location of a file or directory
D) A hidden file path

Solution: (B)
Explanation: Absolute paths start from the root directory (/) and provide the complete location
of a file or directory.

6
Which Linux command lists all files, including hidden ones?

A) ls
B) ls -a
C) ls -l
D) ls -h

Solution: (B)
Explanation: The -a option with ls lists all files, including hidden files (files that start with .).
7
What is the purpose of the pwd command in Linux?
A) To print all files in the directory
B) To display the current working directory
C) To change the current directory
D) To list directory permissions

Solution: (B)
Explanation: The pwd command stands for "print working directory" and displays the current
working directory.

8
Which option with the cp command copies directories recursively?

A) -a
B) -i
C) -R
D) -v

Solution: (C)
Explanation: The -R option enables the cp command to copy directories and their contents
recursively.

9
How does the chmod command modify permissions in symbolic notation?

A) By using numbers like 755


B) By using symbols like u+r
C) By deleting files
D) By renaming files

Solution: (B)
Explanation: In symbolic notation, chmod modifies file permissions using symbols (e.g., u+r
adds read permission for the user).
10
What is the default file created by the touch command?
A) A file with predefined content
B) A directory
C) An empty file
D) A hidden file

Solution: (C)
Explanation: The touch command creates an empty file or updates the timestamp of an
existing file.

11
What does the man command do in Linux?
A) Opens a graphical editor
B) Displays a manual for a command
C) Compiles a program
D) Moves a file

Solution: (B)
Explanation: The man command provides the manual pages for a command, describing its
usage and options.

12
Which command displays running processes in real time?

A) ps
B) grep
C) top
D) exit

Solution: (C)
Explanation: The top command provides a real-time view of running processes, including
CPU and memory usage.
13
What does the grep option -i do?
A) Prints the line number
B) Ignores case sensitivity
C) Inverts the search
D) Counts the number of matches

Solution: (B)
Explanation: The -i option makes the search case-insensitive.

14
Which step comes first in the C compilation process?
A) Linking
B) Preprocessing
C) Assembling
D) Execution

Solution: (B)
Explanation: Preprocessing is the first step in the compilation process, where directives like
#include and macros are processed.

15
In the first C program, what does #include <stdio.h> do?
A) Includes the standard input/output library
B) Declares variables
C) Starts the main function
D) Allocates memory

Solution: (A)
Explanation: #include <stdio.h> allows the use of standard input/output functions like
printf and scanf.

16
Which command compiles a C program?
A) run
B) gcc
C) chmod
D) make

Solution: (B)
Explanation: The gcc command is used to compile C programs.

17
What is the default extension of a compiled C program?

A) .txt
B) .out
C) .exe
D) .c

Solution: (B)
Explanation: The compiled output of a C program typically has the .out extension by default
(e.g., a.out).

18
What does the clear command do in Linux?
A) Deletes all files
B) Clears the terminal screen
C) Displays file permissions
D) Opens a text editor

Solution: (B)
Explanation: The clear command clears the terminal screen.

19
Which of the following options with ps lists all processes?

A) -A
B) -e
C) Both A and B
D) None of the above

Solution: (C)
Explanation: Both -A and -e options with ps display all processes.

20
What does the symbol .. represent in the Linux file system?
A) The current directory
B) The root directory
C) The parent directory
D) A hidden directory

Solution: (C)
Explanation: The .. symbol represents the parent directory of the current working directory.

21
What is the correct octal representation for the permission -rwxr-x--x?

A) 751
B) 741
C) 761
D) 751

Solution: (A)
Explanation: Permissions are translated as rwx=7, r-x=5, and --x=1, so the octal
representation is 751.

22
Which of the following commands recursively deletes a directory and its
contents without confirmation?

A) rm -f
B) rm -rf
C) rmdir
D) rm

Solution: (B)
Explanation: The -rf option with rm deletes directories and their contents recursively without
prompting for confirmation.

23
In Linux, what does the chmod u+w file.txt command do?
A) Removes write permission for the user
B) Grants write permission to the user
C) Grants write permission to others
D) Makes the file executable

Solution: (B)
Explanation: The u+w option adds write permission to the user for file.txt.

24
What does the command grep -v '^#' file.txt do?

A) Displays lines containing #


B) Displays lines starting with #
C) Displays lines not starting with #
D) Displays blank lines

Solution: (C)
Explanation: The -v option inverts the match, so it displays lines that do not start with #.

25
How can you execute a C program compiled file named program in Linux?

A) ./program.c
B) program
C) gcc program.c
D) ./program
Solution: (D)
Explanation: After compilation, the executable file can be run using ./program.

26
How can you find the PID of all currently running processes?

A) ps -p
B) ps -A
C) top -p
D) man -a

Solution: (B)
Explanation: The ps -A command lists all running processes, including their PIDs.

27
What does the -c option in the grep command do?
A) Counts the total matches
B) Displays the matched line numbers
C) Highlights the matches
D) Displays lines without matches

Solution: (A)
Explanation: The -c option counts the number of matching lines.

28
What will happen if chmod 777 file.txt is executed?
A) File will be deleted
B) No changes will occur
C) File will have read, write, and execute permissions for everyone
D) File will only have write permissions

Solution: (C)
Explanation: 777 grants all permissions (read, write, execute) to the user, group, and others.
29
What does chmod 640 file.txt mean?
A) User: read-write, Group: read, Others: no access
B) User: read-only, Group: write-only, Others: execute-only
C) User: read-write-execute, Group: read, Others: write
D) No permissions granted to any user

Solution: (A)
Explanation: In octal format, 640 means: user has read/write (6), group has read (4), others
have no permissions (0).

30
How do you terminate a specific process in Linux?

A) kill
B) terminate
C) exit
D) stop

Solution: (A)
Explanation: The kill command is used to terminate processes by their PID.

31
In Linux, which octal permission grants read and write access to the
user, and only read access to the group and others?

A) 644
B) 755
C) 666
D) 600

Solution: (A)
Explanation: 644 translates to rw- for the user, r-- for the group, and r-- for others.
32
Which of the following commands gives execute permission to the group
for a file named data.txt?

A) chmod +x data.txt
B) chmod g+x data.txt
C) chmod o+x data.txt
D) chmod 777 data.txt

Solution: (B)
Explanation: chmod g+x adds execute (x) permission for the group (g).

33
The /etc directory in Linux is used for which of the following purposes?
A) Storing user-specific files
B) System-wide configuration files
C) Temporary files
D) Executable binaries

Solution: (B)
Explanation: The /etc directory stores system-wide configuration files.

34
Which part of the Linux file system contains temporary files created by
applications?

A) /usr
B) /var
C) /tmp
D) /home

Solution: (C)
Explanation: The /tmp directory stores temporary files that are often deleted upon system
reboot.

35
In the Von Neumann architecture, which component is responsible for
storing both instructions and data?
A) CPU
B) ALU
C) Memory Unit
D) Control Unit

Solution: (C)
Explanation: In the Von Neumann architecture, the memory unit stores both instructions and
data in the same memory space.

36
Which Linux command sets permissions for a file so that only the owner
can read and write it, and no one else has access?

A) chmod 644
B) chmod 700
C) chmod 600
D) chmod 777

Solution: (C)
Explanation: chmod 600 grants read (r) and write (w) permissions only to the owner, while
others have no access.

37
What does the /dev directory contain in Linux?
A) System-wide logs
B) Device files
C) Executable binaries
D) Temporary files

Solution: (B)
Explanation: The /dev directory contains device files for hardware such as disks and
terminals.

38
Which command removes only empty directories in Linux?

A) rm
B) rmdir
C) rm -rf
D) chmod -R

Solution: (B)
Explanation: The rmdir command removes directories, but only if they are empty.

39
What does the command chmod u=rwx, g=rw, o=r file.txt do?

A) Sets 777 permissions for file.txt


B) Grants execute permissions to all users
C) Sets user permissions to rwx, group to rw, and others to r
D) Removes all permissions from others

Solution: (C)
Explanation: This command sets user permissions to rwx, group permissions to rw, and
others to r.

40
What does the /var directory in Linux primarily contain?
A) Temporary files
B) Variable files such as logs and caches
C) System binaries
D) Device files

Solution: (B)
Explanation: /var contains variable data files, such as logs, caches, and spool files.
41
Which command lists all files, including hidden files, in long format in
Linux?

A) ls -l
B) ls -a
C) ls -la
D) ls

Solution: (C)
Explanation: The ls -la command combines -l (long format) and -a (show hidden files)
options.

42
What is the main function of registers in a CPU?
A. Store long-term data
B. Execute arithmetic operations
C. Provide high-speed temporary storage
D. Manage I/O operations

Solution: C
Explanation: Registers are small, high-speed storage locations in the CPU that temporarily
hold data and instructions during processing.

43
Which of the following is NOT a characteristic of RAM?
A. Volatile
B. Temporary storage
C. Stores both data and instructions
D. Non-volatile

Solution: D
Explanation: RAM is volatile, meaning its contents are lost when power is turned off.
Non-volatile memory refers to secondary storage like hard disks.
44
What component performs arithmetic and logical operations in the CPU?
A. Registers
B. Control Unit
C. ALU
D. RAM

Solution: C
Explanation: The ALU (Arithmetic Logic Unit) is responsible for performing arithmetic (e.g.,
addition) and logical (e.g., AND, OR) operations.

45
What is the purpose of secondary memory?
A. Temporarily hold data for the CPU
B. Perform arithmetic operations
C. Provide long-term data storage
D. Manage hardware input

Solution: C
Explanation: Secondary memory is used for long-term storage of data and programs, as it
retains information even when the computer is powered off.

46
What is the main feature of the "Stored Program Concept"?
A. Programs and data are stored on a hard disk
B. Programs modify themselves during execution
C. Instructions and data are stored together in memory
D. Programs are loaded directly into registers

Solution: C
Explanation: The Stored Program Concept allows instructions and data to be stored together
in RAM, facilitating flexible program execution.

47
In the "Execution Stage" of the instruction c = a + b, which of the following steps
occurs?
A. The CPU fetches the instruction from memory
B. The ALU adds the values in two registers
C. The control unit decodes the instruction
D. The CPU stores the result in secondary memory

Solution: B
Explanation: During execution, the ALU adds the values stored in registers (e.g., R0 and R1)
and places the result in another register (e.g., R2).

48
Which of the following instructions involves an arithmetic operation?
A. STORE R2, RAM[c]
B. LOAD R0, RAM[a]
C. ADD R2, R0, R1
D. FETCH RAM[b]

Solution: C
Explanation: The ADD R2, R0, R1 instruction performs an arithmetic operation by adding
the values in registers R0 and R1 and storing the result in R2.

49
Why does the Von Neumann Architecture use RAM instead of directly accessing
secondary memory?
A. RAM is more reliable than secondary memory
B. RAM has higher storage capacity
C. RAM provides faster access speeds than secondary memory
D. RAM is non-volatile

Solution: C
Explanation: RAM is much faster than secondary memory, making it suitable for temporary
storage and quick access by the CPU during program execution.

50
Which directory in the Linux file system stores kernel and boot-related files?
A. /var
B. /boot
C. /usr/bin
D. /lib

Solution: B
Explanation: The /boot directory stores files related to the Linux kernel and bootloader, such
as vmlinuz and grub configuration files.

Module II

Sl Question

1
How many bits are required to represent the decimal number 255 in
binary?
A) 6
B) 8
C) 10
D) 12

Solution: (B)
Explanation: The decimal number 255 is represented as 11111111 in binary, which
requires 8 bits.
2
Convert the hexadecimal number 1A3 to binary.

A) 000110100011
B) 101000011
C) 11010011
D) 100011011

Solution: (A)
Explanation: 1A3 in hexadecimal is 0001 1010 0011 in binary.

3
Which of the following represents the decimal number -10 in
signed magnitude format using 8 bits?

A) 10001010
B) 11110110
C) 10101010
D) 11111010

Solution: (A)
Explanation: In signed magnitude, the most significant bit (MSB) indicates the sign (1
for negative) and the remaining bits store the magnitude.

4
In one’s complement representation, how is the decimal number -5
represented using 4 bits?

A) 1011
B) 1101
C) 1110
D) 0101

Solution: (C)
Explanation: To represent -5 in one’s complement, invert the binary representation
of 5 (0101 → 1010).
5
In two’s complement representation, what is the range of numbers
that can be represented using 8 bits?

A) -127 to 128
B) -128 to 127
C) -256 to 255
D) 0 to 255

Solution: (B)
Explanation: For an n-bit two's complement number, the range is -2^(n-1) to
2^(n-1) - 1.

6
What is the binary representation of 0.625 in fractional binary?

A) 0.101
B) 0.11
C) 0.111
D) 0.100

Solution: (A)
Explanation: Convert 0.625 to binary:

● 0.625 × 2 = 1.25 → 1
● 0.25 × 2 = 0.5 → 0
● 0.5 × 2 = 1.0 → 1
Thus, 0.625 = 0.101 in binary.

7
How is the number -32 represented in 8-bit two's complement
form?

A) 11000000
B) 11100000
C) 10000000
D) 10100000

Solution: (A)
Explanation: Convert 32 to binary (00100000) and take its two's complement
(11000000).

8
Which data type consumes the least memory on a typical system?

A) signed char
B) unsigned short
C) float
D) long

Solution: (A)
Explanation: signed char typically uses 1 byte, while other types require more
memory.

9
How many bits are required to store a float in IEEE 754 single
precision format?
A) 16
B) 32
C) 64
D) 128

Solution: (B)
Explanation: Single precision IEEE 754 format uses 32 bits: 1 for the sign, 8 for the
exponent, and 23 for the mantissa.

10
In IEEE 754 double precision, how many bits are used for the
exponent?
A) 8
B) 10
C) 11
D) 15

Solution: (C)
Explanation: Double precision uses 11 bits for the exponent.

11
What is the hexadecimal representation of the decimal number
255?

A) 0xF0
B) 0xFF
C) 0xF1
D) 0x1FF

Solution: (B)
Explanation: 255 in decimal equals FF in hexadecimal.

12
What is the binary representation of the decimal number -3 in
two's complement (4 bits)?

A) 1011
B) 1101
C) 1110
D) 1001

Solution: (C)
Explanation: Convert 3 to binary (0011) and take its two's complement (1110).

13
Which of the following is a valid range for unsigned char on most
systems?

A) -128 to 127
B) 0 to 255
C) -255 to 255
D) -127 to 128

Solution: (B)
Explanation: unsigned char represents values from 0 to 2^8 - 1.

14
What is the binary representation of the hexadecimal number
0x2A?

A) 110101
B) 101010
C) 100101
D) 111000

Solution: (B)
Explanation: Convert each hex digit (2 = 0010, A = 1010), so 0x2A = 101010.

15
What is the decimal equivalent of the binary number 1101.101?

A) 13.625
B) 14.3125
C) 13.8125
D) 12.625

Solution: (A)
Explanation: 1101 = 13, 0.101 = 0.625. Thus, 1101.101 = 13.625.

16
What does the sign bit indicate in IEEE 754 floating-point
representation?
A) The magnitude of the number
B) The sign of the number (positive/negative)
C) The exponent
D) The normalization status

Solution: (B)
Explanation: The sign bit is 0 for positive and 1 for negative.
17
What is the value of the bias in IEEE 754 single-precision
representation?
A) 127
B) 128
C) 1023
D) 255

Solution: (A)
Explanation: The bias for single-precision is 127, which helps represent exponents
as unsigned integers.

18
What is the normalized representation of 0.0001101 in IEEE 754
single precision?

A) 1.101 × 2^-4
B) 1.101 × 2^-3
C) 1.110 × 2^-4
D) 1.101 × 2^-2

Solution: (A)
Explanation: Normalize by shifting the decimal point 4 places to the right: 1.101 ×
2^-4.

19
What is the largest unsigned integer that can be represented with
16 bits?

A) 65536
B) 65535
C) 32767
D) 32768

Solution: (B)
Explanation: The range of an unsigned n-bit integer is 0 to (2^n - 1). For 16
bits, this is 0 to 65535.

20
What is the decimal equivalent of the hexadecimal number 0x7F?
A) 125
B) 126
C) 127
D) 128

Solution: (C)
Explanation: 7F in hexadecimal is 127 in decimal.

21
In a floating-point number, which part determines the precision of
the value?
A) Sign bit
B) Exponent
C) Mantissa
D) Bias

Solution: (C)
Explanation: The mantissa determines the precision of the value.

22
What is the memory size of a double data type in most systems?
A) 2 bytes
B) 4 bytes
C) 8 bytes
D) 16 bytes

Solution: (C)
Explanation: A double typically takes 8 bytes (64 bits) in most systems.
23
Convert the fractional binary 0.1011 to its decimal equivalent.
A) 0.6875
B) 0.625
C) 0.75
D) 0.8125

Solution: (D)
Explanation: 0.1011 = (1 × 2^-1) + (0 × 2^-2) + (1 × 2^-3) + (1 ×
2^-4) = 0.8125.

24
How many bytes are there in 1 Kilobyte (KB)?
A) 2^8
B) 2^9
C) 2^10
D) 2^11

Solution: (C)
Explanation: 1 KB = 2^10 bytes.

25
Convert 4 MB to bytes.
A) 2^21
B) 2^20
C) 2^22
D) 2^23

Solution: (C)
Explanation: 1 MB = 2^20 bytes. Therefore, 4 MB = 4 * 2^20 = 2^22 bytes.

26
How many bits are in 1 GB?
A) 2^30
B) 2^33
C) 2^31
D) 2^34

Solution: (B)
Explanation: 1 GB = 2^30 bytes. Convert to bits: 2^30 * 8 = 2^33 bits.

27
Convert 256 KB to bytes.
A) 2^16
B) 2^18
C) 2^20
D) 2^22

Solution: (B)
Explanation: 256 KB = 256 * 2^10 = 2^8 * 2^10 = 2^18 bytes.

28
What is the size of 16 KB in bits?
A) 2^16
B) 2^17
C) 2^18
D) 2^19

Solution: (D)
Explanation: 16 KB = 16 * 2^10 bytes = 2^4 * 2^10 = 2^14 bytes. Convert to bits:
2^14 * 8 = 2^19 bits.

29
How many Kilobytes (KB) are in 1 Gigabyte (GB)?
A) 2^8
B) 2^10
C) 2^20
D) 2^18

Solution: (C)
Explanation: 1 GB = 2^30 bytes. 1 KB = 2^10 bytes. Therefore, 1 GB = 2^30 / 2^10 =
2^20 KB.

30
Convert the binary number 10101001 to hexadecimal.
A) A9
B) 99
C) 59
D) AA

Solution: (A)
Explanation: Split into groups of 4 bits: 1010 and 1001. 1010 = A, 1001 = 9. So the
hexadecimal representation is A9.

31
What is the decimal representation of the binary number 11111111 if treated as
an unsigned integer?
A) 127
B) 255
C) -1
D) 256

Solution: (B)
Explanation: 11111111 in unsigned form is 2^8 - 1 = 255.

32
Convert the hexadecimal number 1C3 to decimal.
A) 451
B) 455
C) 467
D) 479

Solution: (C)
Explanation: 1C3 = (1 * 16^2) + (12 * 16^1) + (3 * 16^0) = 256 +
192 + 3 = 451.

33
What is the two's complement of -7 in 4 bits?
A) 1001
B) 1010
C) 1000
D) 1001

Solution: (C)
Explanation: Represent 7 as 0111, then take one's complement: 1000. Add 1 →
1000.

34
What is the two's complement of -18 in 8 bits?
A) 11101110
B) 11101111
C) 11101100
D) 11110010

Solution: (A)
Explanation: Represent 18 as 00010010. Take one's complement: 11101101. Add
1 → 11101110.

35
What is the decimal value of 11111010 in two's complement representation
(8-bit)?
A) -6
B) -5
C) -7
D) -4

Solution: (A)
Explanation: The MSB is 1, so it's negative. Invert the bits: 00000101. Add 1 →
00000110, which is 6. Negative → -6.
36
Which of the following has the largest range of values?
A) signed char
B) unsigned short
C) signed int
D) unsigned long

Solution: (D)
Explanation: The largest range is provided by unsigned long, which depends on
system architecture (e.g., 4 GB on 32-bit).

37
How many distinct values can be represented using an unsigned short data
type (16 bits)?
A) 2^15
B) 2^16 - 1
C) 2^16
D) 2^8

Solution: (C)
Explanation: unsigned short can represent values from 0 to 2^16 - 1, which is
2^16 distinct values.

38
What is the decimal range of a signed char data type?
A) -127 to 128
B) -128 to 127
C) 0 to 255
D) -256 to 256

Solution: (B)
Explanation: A signed char (8 bits) uses the MSB as a sign bit, so the range is
-128 to 127.

39
Convert the decimal number 10.25 to IEEE 754 single-precision format.
A) 01000001001010000000000000000000
B) 01000001001001000000000000000000
C) 11000001001010000000000000000000
D) 01000000101010000000000000000000

Solution: (A)
Explanation: 10.25 → Binary: 1010.01. Normalize: 1.01001 × 2^3.
Sign bit: 0, Exponent: 127 + 3 = 130 (10000010), Mantissa: 010010000....

40
What is the decimal equivalent of the IEEE 754 single-precision number
01000000101000000000000000000000?
A) 5.0
B) 5.25
C) 5.5
D) 6.0

Solution: (A)
Explanation: Extract sign = 0 (positive), Exponent = 129 - 127 = 2, Mantissa =
1.010. Result: 1.25 * 2^2 = 5.0.

41
What is the bias value in IEEE 754 double-precision representation?
A) 1023
B) 127
C) 2047
D) 511

Solution: (A)
Explanation: The bias for double precision is 1023 (2^(n-1) - 1, where k = 11).

42
What is the value of 1011 in one's complement for a negative number?
A) -4
B) -5
C) -6
D) -7

Solution: (D)
Explanation: Invert all bits → 0100 → Decimal 7. Negative → -7.

43
How many kilobytes (KB) are there in 1 MB?
A) 512
B) 1024
C) 2048
D) 4096

Solution: (B)
Explanation: 1 MB = 1024 KB (using powers of 2).

44
How many bits are in 1 Kilobyte (KB)?
A) 1024
B) 2048
C) 8192
D) 81920

Solution: (C)
Explanation: 1 KB = 1024 bytes, and 1 byte = 8 bits, so 1 KB = 1024 * 8 = 8192 bits.

45
Convert the binary number 10110101 to decimal.
A) 173
B) 169
C) 180
D) 168

Solution: (A)
Explanation: 10110101 in decimal is calculated as 1*(2^7) + 0*(2^6) +
1*(2^5) + 1*(2^4) + 0*(2^3) + 1*(2^2) + 0*(2^1) + 1*(2^0) = 173.

46
What is the hexadecimal representation of 10111011?
A) 7B
B) 8B
C) 9B
D) 6B

Solution: (A)
Explanation: 10111011 in binary equals 7B in hexadecimal.

47
What is the decimal value of the two’s complement binary number 11101010?
A) -22
B) -24
C) -26
D) -28

Solution: (A)
Explanation: Invert the bits (00010101), add 1 → 00010110, which is 22.
Therefore, the value is -22.

48
How many bytes are used to represent a float in memory?
A) 2 bytes
B) 4 bytes
C) 8 bytes
D) 16 bytes

Solution: (B)
Explanation: A float is typically represented using 4 bytes (32 bits) in memory.

49
What is the memory size of a short on a 16-bit system?
A) 1 byte
B) 2 bytes
C) 4 bytes
D) 8 bytes

Solution: (B)
Explanation: On a 16-bit system, a short typically uses 2 bytes.

50
Which of the following numbers can be represented exactly as a float in IEEE
754 format?
A) 0.1
B) 0.2
C) 0.25
D) 0.3

Solution: (C)
Explanation: 0.25 can be represented exactly as a float, while others result in
precision errors.
Module III

sl Question

1
Which of the following is used to write a single-line comment in C?
A) //
B) /* */
C) <!-- -->
D) #

Solution: (A)
Explanation: // is used for single-line comments in C, while /* */ is used for
multi-line comments.

2
What happens when a comment is encountered by the compiler?
A) It is compiled as normal code.
B) It is ignored by the compiler.
C) It causes a syntax error.
D) It is treated as a constant.

Solution: (B)
Explanation: Comments are ignored by the compiler as they are meant for
documentation purposes.

3
Which of the following is a valid variable declaration in C?
A) int 1var;
B) int var_1;
C) int #var;
D) int var@;

Solution: (B)
Explanation: Variable names must begin with a letter or an underscore and can
contain letters, digits, or underscores.
4
What happens if you try to modify a constant defined using const?
A) The value is changed.
B) It results in a compilation error.
C) It causes runtime errors.
D) It has no effect.

Solution: (B)
Explanation: A const variable cannot be modified, and attempting to do so results in
a compilation error.

5
Which function is used to read a single character from input in C?
A) scanf()
B) printf()
C) getchar()
D) gets()

Solution: (C)
Explanation: getchar() reads a single character from standard input.

6
What is the correct syntax to print a floating-point number up to 2 decimal places in C?
A) printf("%.2d", num);
B) printf("%.2f", num);
C) printf("%2f", num);
D) printf("%.02f", num);

Solution: (B)
Explanation: The format specifier %.2f ensures that the number is printed up to two

7 What is the output of the following code?

int a = 5;
printf("%d", ++a);

A) 4
B) 5
C) 6
D) Compilation error
Solution: (C)
Explanation: The ++a increments the value of a before it is printed, so the output is 6.

8
Which relational operator is used to check "not equal to" in C?
A) =
B) ==
C) !=
D) <>

Solution: (C)
Explanation: The != operator is used to check inequality.

9
What is the output of the following code?

int a = 1, b = 0;
printf("%d", a && b);

A) 0
B) 1
C) -1
D) Compilation error

Solution: (A)
Explanation: The && operator checks if both operands are true. Since b is 0 (false),
the result is 0.

10
What is the order of precedence for arithmetic operators?
A) *, /, +, -
B) +, -, *, /
C) *, -, +, /
D) -, +, *, /

Solution: (A)
Explanation: Multiplication (*) and division (/) have higher precedence than addition
(+) and subtraction (-).

11
What is the output of sizeof(char) in C?
A) 1
B) 2
C) 4
D) 8

Solution: (A)
Explanation: The size of a char is 1 byte.

12
What type of conversion happens automatically in C?
A) Implicit conversion
B) Explicit conversion
C) Manual conversion
D) None of the above

Solution: (A)
Explanation: Implicit conversion is automatically handled by the compiler.

13
Which of the following is NOT true about comments in C?
A) Comments are ignored by the compiler.
B) Comments can be nested.
C) Multi-line comments are written using /* */.
D) Comments improve code readability.

Solution: (B)

14
Which of the following is an invalid variable name in C?
A) _var123
B) var_123
C) 123var
D) var123
Solution: (C)
Explanation: Variable names cannot start with a digit.

15
What is the maximum length of an identifier in C?
A) 8 characters
B) 16 characters
C) 31 characters
D) Compiler-dependent

Solution: (D)
Explanation: The maximum length of an identifier depends on the compiler but is
usually 31 characters for older compilers and more for modern ones.

16
What is the correct format specifier for a double?
A) %f
B) %lf
C) %d
D) %ld

Solution: (B)
Explanation: %lf is used to print or scan a double value.

17
Which operator has the highest precedence in C?
A) +
B) -
C) *
D) ++

Solution: (D)
Explanation: The ++ operator has the highest precedence.

18
What will be the result of the following code?

int a = 5, b = 2;
printf("%d", a / b);

A) 2
B) 2.5
C) 3
D) Error

Solution: (A)
Explanation: Integer division truncates the decimal part, so the result is 2.

19
What is the output of the following code?

int x = 5;
printf("%d", x == 5);

A) 0
B) 1
C) 5
D) Compilation error

Solution: (B)
Explanation: The relational operator == returns 1 if the condition is true.

20
What is the output of the following code?

printf("%d", !0);

A) 0
B) 1
C) -1
D) Compilation error

Solution: (B)
Explanation: The logical NOT operator ! negates the value. !0 is 1.
21
Which operator has right-to-left associativity?
A) =
B) +
C) *
D) &&

Solution: (A)
Explanation: The assignment operator = has right-to-left associativity.

22
What will be the output of sizeof('a') in C?
A) 1
B) 2
C) 4
D) 8

Solution: (A)
Explanation: A character constant is treated as an integer of size 1 byte.

23
Which of the following is NOT an implicit type conversion?
A) int to float
B) float to int
C) char to int
D) short to int
Solution: (B)
Explanation: float to int requires explicit type casting.

24 What will the output of the following code be?

int x = 10 % 3;
printf("%d", x);

A) 1
B) 2
C) 0
D) Compilation error
Solution: (A)
Explanation: The remainder when 10 is divided by 3 is 1.

25
What is the result of 5 >= 5?
A) 0
B) 1
C) True
D) False

Solution: (B)
Explanation: The relational operator >= returns 1 if the condition is true.

26
What does the following code output?

int x = 0;
printf("%d", x || 5);

A) 0
B) 1
C) 5
D) Compilation error

Solution: (B)
Explanation: || returns 1 if at least one operand is non-zero.

27
Which operator has the lowest precedence in C?
A) &&
B) ||
C) +
D) =

Solution: (D)
Explanation: The assignment operator = has the lowest precedence.

28
What is the result of (float)5/2 in C?
A) 2
B) 2.0
C) 2.5
D) 3

Solution: (C)
Explanation: The cast (float) promotes the integer 5 to a float, so the division is
performed as floating-point division.

29
What is the result of the following code?

int x = 5, y;
y = ++x;
printf("%d %d", x, y);

A) 5 5
B) 6 6
C) 5 6
D) 6 5

Solution: (B)
Explanation: The pre-increment operator increments x before its value is assigned to
y.

30 What is the output of the following code?

int x = 5, y = 6;
printf("%d", !(x < y));

A) 0
B) 1
C) -1
D) Compilation error

Solution: (B)
Explanation: x < y evaluates to 1 (true), and the logical NOT (!) of true is 0.

31 Which operator has the highest precedence among the following?


A) +
B) -
C) *
D) /

Solution: (C)
Explanation: Multiplication (*) and division (/) have higher precedence than addition
(+) and subtraction (-).

32
What does the following code output?

int x = 10;
x += 5;
printf("%d", x);

A) 10
B) 5
C) 15
D) Compilation error

Solution: (C)
Explanation: The compound assignment operator += adds 5 to x, resulting in 15.

33
Which of the following expressions evaluates to true?

int x = 10, y = 20;

A) x > y
B) x != y
C) x >= y
D) x == y

Solution: (B)
Explanation: x != y is true because 10 is not equal to 20.

34
What is the result of the expression 5 > 3 && 2 < 1?
A) 0
B) 1
C) -1
D) Compilation error

Solution: (A)
Explanation: The first condition (5 > 3) is true, but the second (2 < 1) is false.
Logical AND (&&) requires both conditions to be true, so the result is 0 (false).

35
What will be the result of the following code?

int a = 5, b;
b = -(-a);
printf("%d", b);

A) 5
B) -5
C) Undefined
D) Compilation error

Solution: (A)
Explanation: The inner -a negates a, and the outer - restores it to its original value.

36
What will be the output of the following code?

int a = 2, b = 3, c = 4;
printf("%d", a * b + c);
A) 14
B) 20
C) 10
D) 12

Solution: (C)
Explanation: * has higher precedence than +. So, 2 * 3 + 4 = 6 + 4 = 10.

37
What is the result of the following code?

int x = 1, y = 1;
printf("%d", x || y && 0);

A) 1
B) 0
C) -1
D) Compilation error

Solution: (A)
Explanation: Logical AND (&&) has higher precedence than OR (||). So, y && 0 =
0, and x || 0 = 1.

38 What happens if the condition in the if statement is omitted?

if ()
printf("Hello");

3. A) It will compile and run.


B) It will cause a syntax error.
C) It will always print "Hello".
D) Undefined behavior.
Solution: (B)
Explanation: The condition in the if statement is mandatory.
39
What is the output of the following code?

int a = 10, b = 20;


if (a > b)
printf("A");
else if (a == b)
printf("Equal");
else
printf("B");

A) A
B) Equal
C) B
D) Compilation error

Solution: (C)
Explanation: 10 is less than 20, so "B" is printed.

40
What will the following code output?

int a = 5;
if (a == 5)
if (a > 0)
printf("Positive");
else
printf("Negative");

A) Positive
B) Negative
C) Error
D) Undefined

Solution: (A)
Explanation: Both conditions are true, so "Positive" is printed.
41 int x = 5;
if (x = 0)
printf("Zero");
else
printf("Non-zero");

A) Logical error in the if condition.


B) Compilation error.
C) Infinite loop.
D) No error.

Solution: (A)
Explanation: x = 0 assigns 0 to x instead of comparing it. The condition always
evaluates to false.

42
What is the output of the following code?

int x = 3;
switch (x) {
default: printf("Default");
case 3: printf("Three");
}

A) Default
B) Three
C) DefaultThree
D) ThreeDefault

Solution: (C)
Explanation: The default case is executed because there is no break in the case
3 block.

43
What happens if there is no break in a switch case?
A) Compilation error
B) Only the matching case is executed
C) Fall-through to subsequent cases occurs
D) Default case is executed

Solution: (C)
Explanation: Without break, the control falls through to subsequent cases.

44
Which of the following statements is true for if-else constructs in C?
A) The else block is mandatory.
B) There can be multiple else blocks.
C) The if block must always be executed.
D) None of the above.

Solution: (D)
Explanation: None of the statements are true for if-else.

45
What is the output of the following code?

if (0)
printf("True");
else
printf("False");

A) True
B) False
C) Compilation error
D) Undefined

Solution: (B)
Explanation: The condition 0 is false, so the else block is executed.

46
What will be the output of the following code?

int x = 2;
switch(x) {
case 1: printf("One");
case 2: printf("Two");
case 3: printf("Three");
}

A) One
B) Two
C) TwoThree
D) Compilation error

Solution: (C)
Explanation: Without a break statement, all subsequent cases are executed.

47
What is the correct syntax of an if-else statement?
A) if(condition); else;
B) if(condition) {} else {}
C) if(condition) {} else ();
D) if(condition) ; else {}

Solution: (B)
Explanation: The block for if and else must be enclosed in {} if there are multiple
statements.

48
What will the following code output?

int x = 5;
if (x < 0)
printf("Negative");
else if (x == 5)
printf("Equal");
else
printf("Positive");

A) Negative
B) Equal
C) Positive
D) Compilation error

Solution: (B)
Explanation: Since x == 5, "Equal" is printed.

49
What is required in every switch statement?
A) case
B) break
C) default
D) None of the above

Solution: (A)
Explanation: A switch statement must contain at least one case label.

50
If-Else
What will be the output of the following code?
c
Copy code
int x = 5;
if (x > 3)
printf("True");
else
printf("False");

A) True
B) False
C) Error
D) None

Solution: (A)
Explanation: Since x is greater than 3, the condition is true.

You might also like