
Programming Basics: C, C++, Java, and Python
1. Introduction to Programming
Programming is the process of designing and building executable computer programs to accomplish specific tasks. It involves writing code in programming languages to instruct the computer to perform operations like input processing, data computation, and output generation.
2. Evolution of Programming Languages
- C: Developed by Dennis Ritchie in the early 1970s, C is a procedural language used for system-level programming and embedded systems.
- C++: An extension of C developed by Bjarne Stroustrup, C++ introduced object-oriented features such as classes and inheritance.
- Java: Introduced by Sun Microsystems in 1995, Java is platform-independent due to the Java Virtual Machine (JVM).
- Python: Created by Guido van Rossum in the early 1990s, Python is known for its simplicity and readability.
3. Basic Structure of a Program
C and C++
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
Java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Python
print("Hello, World!")
- C/C++: Use
#include
for libraries andmain()
as the entry point. - Java: Requires a class, with the
main
method as the entry point. - Python: No need for explicit main function for simple scripts.
4. Data Types and Variables
Feature | C | C++ | Java | Python |
---|---|---|---|---|
Type system | Static | Static | Static | Dynamic |
Common types | int, char, float, double | Same as C + bool | int, float, char, boolean | int, float, str, bool |
Examples:
- C/C++:
int a = 10;
- Java:
int a = 10;
- Python:
a = 10
5. Input and Output
- C:
- Input:
scanf("%d", &a);
- Output:
printf("%d", a);
- Input:
- C++:
- Input:
cin >> a;
- Output:
cout << a;
- Input:
- Java:
- Input:
Scanner sc = new Scanner(System.in); int a = sc.nextInt();
- Output:
System.out.println(a);
- Input:
- Python:
- Input:
a = input("Enter a number: ")
- Output:
print(a)
- Input:
6. Operators
All four languages support basic arithmetic (+
, -
, *
, /
, %
), relational (==
, !=
, <
, >
), and logical operators (&&
, ||
, !
in C/C++; and
, or
, not
in Python).
7. Control Statements
Conditional Statements
if (a > b) {
printf("A is greater");
} else {
printf("B is greater");
}
- Similar syntax in C, C++, and Java.
- Python uses indentation:
if a > b:
print("A is greater")
else:
print("B is greater")
Loops
- For loop:
- C/C++/Java:
for (int i=0; i<5; i++)
- Python:
for i in range(5):
- C/C++/Java:
- While loop:
- All languages support it with syntax differences.
- Do-while loop:
- Available in C, C++, and Java, not in Python.
8. Functions / Methods
C
int add(int a, int b) {
return a + b;
}
C++ / Java
- Use similar structure with return type, method name, and parameters.
Python
def add(a, b):
return a + b
9. Arrays and Lists
- C/C++: Fixed-size arrays.
int arr[5] = {1, 2, 3, 4, 5};
- Java:
int[] arr = {1, 2, 3};
- Python: Uses lists, which are dynamic.
arr = [1, 2, 3]
10. Object-Oriented Programming (OOP)
- C: Does not support OOP.
- C++, Java, Python: All support OOP concepts.
Class and Object
Java:
class Car {
int speed;
void display() {
System.out.println(speed);
}
}
Python:
class Car:
def __init__(self, speed):
self.speed = speed
def display(self):
print(self.speed)
Key Concepts:
- Encapsulation
- Inheritance
- Polymorphism
- Abstraction
11. Error Handling
- C/C++: Use
errno
, return codes. - Java:
try-catch
blocks. - Python:
try-except
blocks.
try:
a = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero")
12. File Handling
- C/C++: Use
fopen()
,fscanf()
,fprintf()
- Java: Uses
FileReader
,BufferedReader
- Python: Simple syntax
with open("file.txt", "r") as f:
data = f.read()
13. Differences Between the Languages
Feature | C | C++ | Java | Python |
---|---|---|---|---|
Paradigm | Procedural | OOP + Procedural | Pure OOP | Multi-paradigm |
Compilation | Compiler | Compiler | Compiler + JVM | Interpreter |
Platform | Platform-dependent | Platform-dependent | Platform-independent | Platform-independent |
Memory management | Manual (malloc/free) | Manual | Garbage Collector | Garbage Collector |
Syntax complexity | Medium | Complex | Verbose | Simple and clear |
14. When to Use Which Language
- C: Embedded systems, operating systems, performance-critical code.
- C++: Game development, system software, real-time simulations.
- Java: Enterprise applications, Android apps, large-scale systems.
- Python: Scripting, automation, data science, machine learning, web apps.
15. Conclusion
Understanding the basics of programming through C, C++, Java, and Python gives a strong foundation for further learning. While C and C++ are closer to hardware and offer fine-grained control, Java and Python are higher-level languages designed for productivity and ease of use.
Each language has its strengths:
- C: Best for low-level programming.
- C++: Excellent for performance-critical applications with OOP.
- Java: Best for cross-platform development with a vast ecosystem.
- Python: Ideal for beginners and rapidly growing in data science and automation domains.
Grasping the syntax, structure, and flow control common to these languages sets the stage for more advanced learning in software development, algorithms, data structures, and application design.
✅ Programming Basics – Objective Questions with Answers (1 to 50)
- Which of the following is a compiled language?
A) Python
B) JavaScript
C) C
D) HTML
Answer: C) C - Which symbol is used for a single-line comment in Python?
A) //
B) <!–
C) #
D) /*
Answer: C) # - Which of the following is not a valid data type in C?
A) int
B) float
C) string
D) char
Answer: C) string - Java is platform-________.
A) Specific
B) Dependent
C) Independent
D) Complex
Answer: C) Independent - Which keyword is used to define a function in Python?
A) function
B) def
C) fun
D) void
Answer: B) def - Which of the following is used to declare a constant in C?
A) #define
B) const
C) final
D) immutable
Answer: A) #define - Which of these is not a loop structure?
A) for
B) while
C) loop
D) do-while
Answer: C) loop - What does the ‘++’ operator do in C++?
A) Adds 2
B) Multiplies by 2
C) Increments by 1
D) Decrements by 1
Answer: C) Increments by 1 - Which language is known for indentation-based syntax?
A) C
B) Java
C) C++
D) Python
Answer: D) Python - Which of the following is a valid variable name in Python?
A) 1value
B) value1
C) value-1
D) value 1
Answer: B) value1
- Which keyword is used for inheritance in Java?
A) implements
B) inherits
C) extends
D) interface
Answer: C) extends - Which of the following is used to compile C++ code?
A) javac
B) gcc
C) py
D) node
Answer: B) gcc - Which operator is used for assignment in programming?
A) =
B) ==
C) :=
D) ===
Answer: A) = - Which of the following is not a keyword in C?
A) auto
B) register
C) include
D) void
Answer: C) include - What is the extension of a Python file?
A) .txt
B) .java
C) .py
D) .exe
Answer: C) .py - What will
print(3**2)
output in Python?
A) 6
B) 9
C) 8
D) 32
Answer: B) 9 - In Java, arrays are ___________.
A) Objects
B) Variables
C) Functions
D) None
Answer: A) Objects - Which of the following symbols is used to denote a pointer in C?
A) &
B) *
C) @
D) ^
Answer: B) * - Which of the following is the correct way to declare a variable in Java?
A) int num = 5;
B) num = int 5;
C) 5 = int num;
D) variable int num;
Answer: A) int num = 5; - Which method is used to read input from user in Python 3?
A) scanf()
B) cin>>
C) input()
D) gets()
Answer: C) input()
- Which function is used to output text in C?
A) cout
B) print()
C) printf()
D) echo
Answer: C) printf() - Which of the following is not an OOP concept?
A) Encapsulation
B) Inheritance
C) Compilation
D) Polymorphism
Answer: C) Compilation - Which keyword is used to define a class in Python?
A) object
B) class
C) define
D) struct
Answer: B) class - Which one is used to terminate a statement in C++?
A) ,
B) .
C) :
D) ;
Answer: D) ; - Java code is first compiled into:
A) Assembly code
B) Bytecode
C) Executable
D) Object code
Answer: B) Bytecode - Which is the correct way to start a for loop in C?
A) for i=1 to 10
B) for(int i=0; i<10; i++)
C) for(i in range(10))
D) foreach i in 1..10
Answer: B) for(int i=0; i<10; i++) - Which function is used to get string input in C++?
A) scanf
B) getline
C) cin
D) input
Answer: C) cin - Which of the following is dynamically typed?
A) C
B) C++
C) Java
D) Python
Answer: D) Python - What is the default return type of a function in C if not specified?
A) float
B) int
C) void
D) char
Answer: B) int - Which of these is not a valid loop in Python?
A) for
B) while
C) do-while
D) None
Answer: C) do-while
- Which of these is used to import libraries in Python?
A) using
B) import
C) include
D) require
Answer: B) import - Which character is used to access members in Java?
A) :
B) ->
C) .
D) ::
Answer: C) . - Which function is used to print in Java?
A) echo
B) print()
C) printf()
D) System.out.println()
Answer: D) System.out.println() - Which of the following is not a valid operator in C?
A) +
B) &&
C) **
D) /
Answer: C) ** - Which of the following is used to comment in Java?
A) //
B) #
C) —
D) ;
Answer: A) // - Which loop guarantees at least one execution?
A) for
B) while
C) do-while
D) foreach
Answer: C) do-while - Which one is not a keyword in Java?
A) static
B) final
C) Integer
D) this
Answer: C) Integer - Which keyword is used for function in C?
A) def
B) function
C) void
D) sub
Answer: C) void - Which character is used to indicate a preprocessor directive in C?
A) $
B) &
C) #
D) %
Answer: C) # - Which of these is a mutable data type in Python?
A) tuple
B) int
C) list
D) str
Answer: C) list
- What does JVM stand for?
A) Java Visual Machine
B) Java Virtual Machine
C) Java Variable Mode
D) Java Vendor Method
Answer: B) Java Virtual Machine - In C++, what is the default access specifier for class members?
A) public
B) private
C) protected
D) static
Answer: B) private - Which of the following is not a primitive data type in Java?
A) int
B) float
C) String
D) char
Answer: C) String - Which of these can hold multiple values?
A) float
B) int
C) array
D) char
Answer: C) array - Which is used for modular programming in Python?
A) functions
B) variables
C) classes
D) modules
Answer: D) modules - What will be the output of
print("Hello" + "World")
?
A) HelloWorld
B) Hello World
C) Hello+World
D) Error
Answer: A) HelloWorld - Which of the following is a correct array declaration in C?
A) int arr();
B) int arr[10];
C) array arr[10];
D) int arr{};
Answer: B) int arr[10]; - Which of the following is a correct variable declaration in C++?
A) int 1x;
B) int x1;
C) x int;
D) var x;
Answer: B) int x1; - Which language uses indentation to define blocks of code?
A) Java
B) C++
C) Python
D) C
Answer: C) Python - Which of these is used for exception handling in Java?
A) catch
B) try
C) throw
D) All of the above
Answer: D) All of the above
✅ Programming Basics – Objective Questions with Answers (51 to 100)
- Which keyword is used to create an object in Java?
A) new
B) create
C) malloc
D) object
Answer: A) new - What is the output of
len("Hello")
in Python?
A) 4
B) 5
C) 6
D) Error
Answer: B) 5 - Which of the following is used to read input in Java?
A) cin
B) input()
C) Scanner
D) gets()
Answer: C) Scanner - Which keyword is used to declare a constant in Java?
A) constant
B) const
C) static
D) final
Answer: D) final - Which header file is required for
printf()
in C?
A) stdlib.h
B) string.h
C) conio.h
D) stdio.h
Answer: D) stdio.h - Which of the following is an escape character?
A) /
B) //
C) \n
D) #
Answer: C) \n - Which of these is not a valid Python data type?
A) list
B) dict
C) float
D) real
Answer: D) real - Which of the following is a character constant in C?
A) “A”
B) ‘A’
C) A
D) ‘AB’
Answer: B) ‘A’ - Which method is used to convert a string to lowercase in Python?
A) str.lowercase()
B) lower()
C) tolower()
D) string.lower()
Answer: B) lower() - Which of the following can be overloaded in C++?
A) Operators
B) Constructors
C) Functions
D) All of the above
Answer: D) All of the above
- What is the output of
3 + 2 * 2
in Python?
A) 10
B) 7
C) 8
D) 9
Answer: B) 7 - Which of the following is not a valid loop keyword in Java?
A) for
B) loop
C) while
D) do
Answer: B) loop - Which function returns the remainder in C?
A) divide()
B) mod()
C) %
D) rem()
Answer: C) % - What is used to exit from a loop in C/C++?
A) exit
B) break
C) continue
D) stop
Answer: B) break - Which of these keywords is used to define a class in Java?
A) def
B) struct
C) class
D) function
Answer: C) class - Which function is used to allocate memory dynamically in C?
A) new
B) malloc()
C) alloc()
D) define()
Answer: B) malloc() - Which of the following is used for single-line comment in C++?
A) #
B) //
C) /*
D) —
Answer: B) // - In Java, which of these is not a primitive data type?
A) int
B) double
C) String
D) boolean
Answer: C) String - Which statement is true about Python?
A) It’s statically typed
B) It’s compiled
C) It uses indentation
D) It’s only for web development
Answer: C) It uses indentation - Which function is used to find the size of a variable in C?
A) size()
B) length()
C) sizeof()
D) size_of()
Answer: C) sizeof()
- Which keyword is used to prevent inheritance in Java?
A) static
B) final
C) const
D) void
Answer: B) final - Which of the following is a ternary operator in C?
A) ? :
B) ++
C) &&
D) <>
Answer: A) ? : - Which method is used to add an element in a Python list?
A) insert()
B) add()
C) append()
D) push()
Answer: C) append() - Which function is used to find square root in C?
A) sqrt()
B) square()
C) power()
D) root()
Answer: A) sqrt() - Which one is not a valid access modifier in Java?
A) private
B) protected
C) hidden
D) public
Answer: C) hidden - Which of the following is used for file handling in Python?
A) open()
B) file()
C) fopen()
D) read()
Answer: A) open() - Which keyword is used to stop a function and return a value in C?
A) stop
B) exit
C) return
D) break
Answer: C) return - Which of the following denotes a string in Python?
A) “Hello”
B) ‘Hello’
C) ”’Hello”’
D) All of the above
Answer: D) All of the above - What is the default value of an uninitialized int in C?
A) 0
B) Null
C) Garbage value
D) -1
Answer: C) Garbage value - Which of the following is used to catch exceptions in Java?
A) try
B) except
C) catch
D) try-catch
Answer: D) try-catch
- Which is the correct format for a for loop in Python?
A) for(i=0; i<5; i++)
B) for i in 5
C) for i in range(5):
D) foreach i in 5
Answer: C) for i in range(5): - Which of these is a keyword in C++?
A) variable
B) return
C) function
D) define
Answer: B) return - Which keyword is used to define a structure in C?
A) struct
B) object
C) class
D) record
Answer: A) struct - Which function is used to convert string to integer in Python?
A) str()
B) int()
C) parseInt()
D) number()
Answer: B) int() - What is the return type of
main()
in C?
A) void
B) int
C) char
D) double
Answer: B) int - Which of the following is used to create a comment block in C?
A) //…//
B)
C) /…/
D) #…#
Answer: C) /…/ - Which data type is used for decimal numbers in Python?
A) int
B) str
C) float
D) char
Answer: C) float - Which function is used to exit a program in C?
A) return()
B) quit()
C) stop()
D) exit()
Answer: D) exit() - Which is the correct way to start a Java program?
A) main()
B) start()
C) public static void main(String[] args)
D) begin()
Answer: C) public static void main(String[] args) - Which of these is a relational operator?
A) =
B) ==
C) :=
D) !==
Answer: B) ==
- What is the result of
4 // 2
in Python?
A) 2.0
B) 2
C) 2.5
D) 1
Answer: B) 2 - Which function is used to get string length in C?
A) len()
B) strlen()
C) length()
D) strlength()
Answer: B) strlen() - Which of these is an IDE for Python?
A) Eclipse
B) Turbo C
C) PyCharm
D) NetBeans
Answer: C) PyCharm - Which data type stores only True/False in Python?
A) bit
B) int
C) boolean
D) bool
Answer: D) bool - Which of these is used to allocate memory in C++?
A) malloc
B) new
C) calloc
D) alloc
Answer: B) new - Which keyword is used to inherit a class in C++?
A) extends
B) :
C) inherits
D) implements
Answer: B) : - What is the extension of a compiled Java file?
A) .java
B) .exe
C) .class
D) .jclass
Answer: C) .class - Which Python keyword is used for error handling?
A) try
B) handle
C) error
D) raise
Answer: A) try - Which of these symbols is used to access members in C++?
A) .
B) ->
C) ::
D) All of the above
Answer: D) All of the above - Which function is used to convert lowercase to uppercase in Python?
A) up()
B) upper()
C) uppercase()
D) toUpper()
Answer: B) upper()
✅ Programming Basics – Objective Questions with Answers (101 to 150)
- Which of the following is not a keyword in C?
A) switch
B) typedef
C) class
D) goto
Answer: C) class - Which of the following is not a valid variable name in Python?
A) my_var
B) _var
C) 2var
D) var2
Answer: C) 2var - Which function is used to read a character in C?
A) getchar()
B) readchar()
C) scanchar()
D) getch()
Answer: A) getchar() - Which operator is used to concatenate strings in Python?
A) +
B) &
C) .
D) *
Answer: A) + - Which of the following is a logical operator in C?
A) &&
B) ++
C) ::
D) ?:
Answer: A) && - What does IDE stand for?
A) Integrated Design Engine
B) Internal Development Environment
C) Integrated Development Environment
D) Internet Debug Engine
Answer: C) Integrated Development Environment - Which of the following is used for inheritance in Java?
A) extends
B) inherits
C) :
D) base
Answer: A) extends - Which of the following is a correct function definition in Python?
A) function myfun():
B) def myfun():
C) fun myfun():
D) void myfun():
Answer: B) def myfun(): - Which keyword is used to define a function in C?
A) def
B) define
C) function
D) return type + name (e.g., int sum())
Answer: D) return type + name (e.g., int sum()) - Which of the following is not a loop structure in Python?
A) for
B) while
C) do-while
D) None of the above
Answer: C) do-while
- Which function is used to write output in C++?
A) print()
B) write()
C) cout
D) echo()
Answer: C) cout - Which module in Python is used for math functions?
A) math
B) calc
C) numbers
D) numerical
Answer: A) math - Which symbol is used for comments in Python?
A) //
B) #
C)
D) /* */
Answer: B) # - What will be the output of:
5 == 5
in Python?
A) True
B) False
C) 1
D) Error
Answer: A) True - Which access modifier allows access within the same class in Java?
A) public
B) private
C) protected
D) default
Answer: B) private - Which keyword is used to define a macro in C?
A) macro
B) define
C) #define
D) const
Answer: C) #define - Which one is not a valid C++ data type?
A) int
B) float
C) real
D) char
Answer: C) real - In Python, how do you get the last item of a list
myList
?
A) myList[0]
B) myList[-1]
C) myList[last]
D) myList[length]
Answer: B) myList[-1] - What does JVM stand for?
A) Java Virtual Memory
B) Java Visual Machine
C) Java Virtual Machine
D) Java Verified Module
Answer: C) Java Virtual Machine - Which of the following is not a valid function in C?
A) main()
B) printf()
C) input()
D) scanf()
Answer: C) input()
- Which operator is used to raise power in Python?
A) ^
B) pow
C) **
D) ^^
Answer: C) ** - Which one of the following is used to terminate a statement in C++?
A) :
B) ;
C) .
D) ,
Answer: B) ; - Which function is used to get input from user in Python?
A) scanf()
B) input()
C) cin>>
D) gets()
Answer: B) input() - Which keyword is used to create a class in C++?
A) struct
B) class
C) object
D) type
Answer: B) class - Which of these is a valid Python list?
A) {1, 2, 3}
B) (1, 2, 3)
C) [1, 2, 3]
D) <1, 2, 3>
Answer: C) [1, 2, 3] - Which header file is required for string functions in C?
A) string.h
B) str.h
C) strings.h
D) cstring.h
Answer: A) string.h - Which of the following is a mutable data type in Python?
A) tuple
B) list
C) string
D) int
Answer: B) list - What is the extension of Python files?
A) .py
B) .pt
C) .python
D) .pyt
Answer: A) .py - Which of the following is an example of dynamic memory allocation in C?
A) malloc()
B) int x;
C) scanf()
D) sizeof()
Answer: A) malloc() - Which of the following languages supports both procedural and OOP paradigms?
A) C
B) C++
C) Python
D) Both B and C
Answer: D) Both B and C
- What does
int x = 10 / 3;
store in C?
A) 3
B) 3.33
C) 4
D) Error
Answer: A) 3 - Which Python data structure is best for key-value pairs?
A) list
B) tuple
C) dict
D) set
Answer: C) dict - Which of these is not a feature of Java?
A) Platform independent
B) Object oriented
C) Manual memory management
D) Robust
Answer: C) Manual memory management - Which of the following is not allowed in variable names in C?
A) _
B) 0-9
C) space
D) letters
Answer: C) space - Which statement is used for conditional execution in Python?
A) if
B) when
C) switch
D) select
Answer: A) if - Which is not a valid file mode in Python?
A) ‘r’
B) ‘w’
C) ‘rw’
D) ‘a’
Answer: C) ‘rw’ - Which keyword is used to handle exceptions in Python?
A) catch
B) handle
C) except
D) error
Answer: C) except - Which of the following is a bitwise operator in C?
A) &&
B) ||
C) &
D) <>
Answer: C) & - Which function is used to convert a string to float in Python?
A) float()
B) str()
C) double()
D) convert()
Answer: A) float() - Which function is used to print something in Python?
A) echo()
B) print()
C) display()
D) write()
Answer: B) print()
- What is the size of
int
in C (standard 32-bit)?
A) 2 bytes
B) 4 bytes
C) 8 bytes
D) 1 byte
Answer: B) 4 bytes - Which of these is a type of loop?
A) repeat-until
B) for
C) start
D) case
Answer: B) for - Which keyword is used to define a constant in C?
A) const
B) final
C) constant
D) define
Answer: A) const - What is used to read input from the console in C++?
A) input()
B) scanf()
C) cin
D) read()
Answer: C) cin - Which of these can store multiple data types in Python?
A) list
B) tuple
C) dict
D) All of the above
Answer: D) All of the above - Which of the following is an OOP principle?
A) Encapsulation
B) Looping
C) Typing
D) Scanning
Answer: A) Encapsulation - Which operator is used for not equal in C++?
A) /=
B) !=
C) <>
D) not=
Answer: B) != - Which character is used for newline in Python?
A) /n
B) \n
C) \r
D) ^n
Answer: B) \n - Which header file is required for mathematical functions in C?
A) math.h
B) calc.h
C) cmath
D) stdlib.h
Answer: A) math.h - Which of the following is a feature of Python?
A) Interpreted
B) Compiled
C) Static typing
D) Low-level
Answer: A) Interpreted
✅ Programming Basics – Objective Questions with Answers (151 to 200)
- Which of the following is used to start a comment in C++?
A) /*
B) //
C) #
D) <!–
Answer: B) // - Which keyword is used to declare a class in Java?
A) class
B) Class
C) struct
D) object
Answer: A) class - Which is the correct syntax to open a file in read mode in Python?
A) open(“file.txt”, “r”)
B) open(“file.txt”, “read”)
C) open.read(“file.txt”)
D) openfile(“file.txt”, “r”)
Answer: A) open(“file.txt”, “r”) - What is the default return type of
main()
in C?
A) void
B) int
C) float
D) char
Answer: B) int - Which symbol is used for address-of operator in C?
A) *
B) &
C) %
D) @
Answer: B) & - What will
print(2 ** 3)
output in Python?
A) 6
B) 8
C) 9
D) 5
Answer: B) 8 - Which of the following is a loop structure in Java?
A) for
B) while
C) do-while
D) All of the above
Answer: D) All of the above - What will be the output of
print(len("Hello"))
in Python?
A) 4
B) 5
C) 6
D) Error
Answer: B) 5 - Which of the following is a valid character constant in C?
A) “A”
B) A
C) ‘A’
D) ‘A’
Answer: C) ‘A’ - Which one of the following is not a feature of C++?
A) Object-oriented
B) Supports classes
C) Garbage collection
D) Function overloading
Answer: C) Garbage collection
- Which of the following is used for decision making in C?
A) for
B) while
C) if
D) goto
Answer: C) if - Which of these is not a primitive data type in Java?
A) int
B) float
C) boolean
D) String
Answer: D) String - In Python, which of these is a tuple?
A) [1, 2, 3]
B) {1, 2, 3}
C) (1, 2, 3)
D) <1, 2, 3>
Answer: C) (1, 2, 3) - Which of the following keywords is used to stop a loop in C?
A) end
B) break
C) exit
D) return
Answer: B) break - Which operator is used for assignment in all languages?
A) ==
B) :=
C) =
D) =>
Answer: C) = - Which is the correct way to declare a variable in Python?
A) int x = 5
B) x = 5
C) declare x = 5
D) var x = 5
Answer: B) x = 5 - Which operator is used to compare two values in C?
A) =
B) :=
C) ==
D) =>
Answer: C) == - In Java, which of these is not a loop?
A) for
B) while
C) do-while
D) repeat-until
Answer: D) repeat-until - Which of the following functions can convert string to integer in Python?
A) string()
B) int()
C) input()
D) str()
Answer: B) int() - Which of these is the escape character in C?
A) /
B) \
C) #
D) %
Answer: B) \
- What is the correct way to declare an array in C?
A) array[10];
B) int arr[10];
C) int arr;
D) declare arr[10];
Answer: B) int arr[10]; - Which of these is not a valid loop in Python?
A) for
B) while
C) do
D) None
Answer: C) do - Which of these is not a valid Java identifier?
A) myVar
B) 2value
C) _value
D) $amount
Answer: B) 2value - Which is used to define a function in C++?
A) void func() {}
B) function func() {}
C) def func():
D) func = function()
Answer: A) void func() {} - Which data type is used to store decimal numbers in Python?
A) int
B) str
C) float
D) bool
Answer: C) float - Which function is used to determine the length of a string in C?
A) size()
B) len()
C) length()
D) strlen()
Answer: D) strlen() - Which of these is used to comment in Java?
A) #
B) //
C)
D) —
Answer: B) // - In Python,
list(range(3))
gives:
A) [0, 1, 2]
B) [1, 2, 3]
C) (0, 1, 2)
D) {0, 1, 2}
Answer: A) [0, 1, 2] - Which of these is not a built-in function in C?
A) printf()
B) scanf()
C) input()
D) gets()
Answer: C) input() - Which keyword is used to create a method in Java?
A) method
B) def
C) function
D) void
Answer: D) void
- Which character is used to include headers in C?
A) &
B) #
C) %
D) @
Answer: B) # - Which Python keyword is used to handle errors?
A) error
B) handle
C) try
D) catch
Answer: C) try - Which data type can hold only True or False?
A) int
B) float
C) bool
D) char
Answer: C) bool - Which of the following is a post-increment operator in C++?
A) ++i
B) i++
C) i+=
D) i=+
Answer: B) i++ - Which is the default access specifier in C++?
A) private
B) protected
C) public
D) None
Answer: A) private - Which of these is not a Python loop keyword?
A) for
B) while
C) do
D) break
Answer: C) do - Which of the following is not a Python keyword?
A) lambda
B) try
C) then
D) with
Answer: C) then - In C, which function is used to find the square root?
A) sqrt()
B) root()
C) sqr()
D) pow()
Answer: A) sqrt() - Which keyword is used to inherit a class in C++?
A) base
B) public
C) extend
D) super
Answer: B) public - Which of these is used to define a block in Python?
A) {}
B) ()
C) : and indentation
D) ;
Answer: C) : and indentation
- Which header file includes
printf()
in C?
A) stdlib.h
B) math.h
C) stdio.h
D) string.h
Answer: C) stdio.h - What will
type(3.5)
return in Python?
A) int
B) double
C) float
D) str
Answer: C) float - Which operator is used for modulus in C?
A) /
B) //
C) %
D) \
Answer: C) % - Which one is a Python IDE?
A) Turbo C
B) Dev C++
C) PyCharm
D) Eclipse C
Answer: C) PyCharm - Which one is used for inheritance in Python?
A) base
B) extends
C) :
D) (ParentClass)
Answer: D) (ParentClass) - Which function is used to round numbers in Python?
A) round()
B) floor()
C) ceil()
D) fix()
Answer: A) round() - What is
None
in Python?
A) A number
B) A boolean
C) A special constant
D) A function
Answer: C) A special constant - Which function is used to find maximum in Python?
A) max()
B) greatest()
C) top()
D) highest()
Answer: A) max() - Which operator is used for logical AND in Python?
A) &&
B) and
C) &
D) AND
Answer: B) and - What is the output of
print(10 // 3)
in Python?
A) 3.33
B) 3
C) 3.0
D) 4
Answer: B) 3