Programming Basics (C, C++, Java, Python – only basic knowledge)


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 and main() 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

FeatureCC++JavaPython
Type systemStaticStaticStaticDynamic
Common typesint, char, float, doubleSame as C + boolint, float, char, booleanint, 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);
  • C++:
    • Input: cin >> a;
    • Output: cout << a;
  • Java:
    • Input: Scanner sc = new Scanner(System.in); int a = sc.nextInt();
    • Output: System.out.println(a);
  • Python:
    • Input: a = input("Enter a number: ")
    • Output: print(a)

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):
  • 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

FeatureCC++JavaPython
ParadigmProceduralOOP + ProceduralPure OOPMulti-paradigm
CompilationCompilerCompilerCompiler + JVMInterpreter
PlatformPlatform-dependentPlatform-dependentPlatform-independentPlatform-independent
Memory managementManual (malloc/free)ManualGarbage CollectorGarbage Collector
Syntax complexityMediumComplexVerboseSimple 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)

  1. Which of the following is a compiled language?
    A) Python
    B) JavaScript
    C) C
    D) HTML
    Answer: C) C
  2. Which symbol is used for a single-line comment in Python?
    A) //
    B) <!–
    C) #
    D) /*
    Answer: C) #
  3. Which of the following is not a valid data type in C?
    A) int
    B) float
    C) string
    D) char
    Answer: C) string
  4. Java is platform-________.
    A) Specific
    B) Dependent
    C) Independent
    D) Complex
    Answer: C) Independent
  5. Which keyword is used to define a function in Python?
    A) function
    B) def
    C) fun
    D) void
    Answer: B) def
  6. Which of the following is used to declare a constant in C?
    A) #define
    B) const
    C) final
    D) immutable
    Answer: A) #define
  7. Which of these is not a loop structure?
    A) for
    B) while
    C) loop
    D) do-while
    Answer: C) loop
  8. 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
  9. Which language is known for indentation-based syntax?
    A) C
    B) Java
    C) C++
    D) Python
    Answer: D) Python
  10. Which of the following is a valid variable name in Python?
    A) 1value
    B) value1
    C) value-1
    D) value 1
    Answer: B) value1

  1. Which keyword is used for inheritance in Java?
    A) implements
    B) inherits
    C) extends
    D) interface
    Answer: C) extends
  2. Which of the following is used to compile C++ code?
    A) javac
    B) gcc
    C) py
    D) node
    Answer: B) gcc
  3. Which operator is used for assignment in programming?
    A) =
    B) ==
    C) :=
    D) ===
    Answer: A) =
  4. Which of the following is not a keyword in C?
    A) auto
    B) register
    C) include
    D) void
    Answer: C) include
  5. What is the extension of a Python file?
    A) .txt
    B) .java
    C) .py
    D) .exe
    Answer: C) .py
  6. What will print(3**2) output in Python?
    A) 6
    B) 9
    C) 8
    D) 32
    Answer: B) 9
  7. In Java, arrays are ___________.
    A) Objects
    B) Variables
    C) Functions
    D) None
    Answer: A) Objects
  8. Which of the following symbols is used to denote a pointer in C?
    A) &
    B) *
    C) @
    D) ^
    Answer: B) *
  9. 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;
  10. Which method is used to read input from user in Python 3?
    A) scanf()
    B) cin>>
    C) input()
    D) gets()
    Answer: C) input()

  1. Which function is used to output text in C?
    A) cout
    B) print()
    C) printf()
    D) echo
    Answer: C) printf()
  2. Which of the following is not an OOP concept?
    A) Encapsulation
    B) Inheritance
    C) Compilation
    D) Polymorphism
    Answer: C) Compilation
  3. Which keyword is used to define a class in Python?
    A) object
    B) class
    C) define
    D) struct
    Answer: B) class
  4. Which one is used to terminate a statement in C++?
    A) ,
    B) .
    C) :
    D) ;
    Answer: D) ;
  5. Java code is first compiled into:
    A) Assembly code
    B) Bytecode
    C) Executable
    D) Object code
    Answer: B) Bytecode
  6. 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++)
  7. Which function is used to get string input in C++?
    A) scanf
    B) getline
    C) cin
    D) input
    Answer: C) cin
  8. Which of the following is dynamically typed?
    A) C
    B) C++
    C) Java
    D) Python
    Answer: D) Python
  9. 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
  10. Which of these is not a valid loop in Python?
    A) for
    B) while
    C) do-while
    D) None
    Answer: C) do-while

  1. Which of these is used to import libraries in Python?
    A) using
    B) import
    C) include
    D) require
    Answer: B) import
  2. Which character is used to access members in Java?
    A) :
    B) ->
    C) .
    D) ::
    Answer: C) .
  3. Which function is used to print in Java?
    A) echo
    B) print()
    C) printf()
    D) System.out.println()
    Answer: D) System.out.println()
  4. Which of the following is not a valid operator in C?
    A) +
    B) &&
    C) **
    D) /
    Answer: C) **
  5. Which of the following is used to comment in Java?
    A) //
    B) #
    C) —
    D) ;
    Answer: A) //
  6. Which loop guarantees at least one execution?
    A) for
    B) while
    C) do-while
    D) foreach
    Answer: C) do-while
  7. Which one is not a keyword in Java?
    A) static
    B) final
    C) Integer
    D) this
    Answer: C) Integer
  8. Which keyword is used for function in C?
    A) def
    B) function
    C) void
    D) sub
    Answer: C) void
  9. Which character is used to indicate a preprocessor directive in C?
    A) $
    B) &
    C) #
    D) %
    Answer: C) #
  10. Which of these is a mutable data type in Python?
    A) tuple
    B) int
    C) list
    D) str
    Answer: C) list

  1. 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
  2. In C++, what is the default access specifier for class members?
    A) public
    B) private
    C) protected
    D) static
    Answer: B) private
  3. Which of the following is not a primitive data type in Java?
    A) int
    B) float
    C) String
    D) char
    Answer: C) String
  4. Which of these can hold multiple values?
    A) float
    B) int
    C) array
    D) char
    Answer: C) array
  5. Which is used for modular programming in Python?
    A) functions
    B) variables
    C) classes
    D) modules
    Answer: D) modules
  6. What will be the output of print("Hello" + "World")?
    A) HelloWorld
    B) Hello World
    C) Hello+World
    D) Error
    Answer: A) HelloWorld
  7. 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];
  8. 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;
  9. Which language uses indentation to define blocks of code?
    A) Java
    B) C++
    C) Python
    D) C
    Answer: C) Python
  10. 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)

  1. Which keyword is used to create an object in Java?
    A) new
    B) create
    C) malloc
    D) object
    Answer: A) new
  2. What is the output of len("Hello") in Python?
    A) 4
    B) 5
    C) 6
    D) Error
    Answer: B) 5
  3. Which of the following is used to read input in Java?
    A) cin
    B) input()
    C) Scanner
    D) gets()
    Answer: C) Scanner
  4. Which keyword is used to declare a constant in Java?
    A) constant
    B) const
    C) static
    D) final
    Answer: D) final
  5. 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
  6. Which of the following is an escape character?
    A) /
    B) //
    C) \n
    D) #
    Answer: C) \n
  7. Which of these is not a valid Python data type?
    A) list
    B) dict
    C) float
    D) real
    Answer: D) real
  8. Which of the following is a character constant in C?
    A) “A”
    B) ‘A’
    C) A
    D) ‘AB’
    Answer: B) ‘A’
  9. 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()
  10. 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

  1. What is the output of 3 + 2 * 2 in Python?
    A) 10
    B) 7
    C) 8
    D) 9
    Answer: B) 7
  2. Which of the following is not a valid loop keyword in Java?
    A) for
    B) loop
    C) while
    D) do
    Answer: B) loop
  3. Which function returns the remainder in C?
    A) divide()
    B) mod()
    C) %
    D) rem()
    Answer: C) %
  4. What is used to exit from a loop in C/C++?
    A) exit
    B) break
    C) continue
    D) stop
    Answer: B) break
  5. Which of these keywords is used to define a class in Java?
    A) def
    B) struct
    C) class
    D) function
    Answer: C) class
  6. Which function is used to allocate memory dynamically in C?
    A) new
    B) malloc()
    C) alloc()
    D) define()
    Answer: B) malloc()
  7. Which of the following is used for single-line comment in C++?
    A) #
    B) //
    C) /*
    D) —
    Answer: B) //
  8. In Java, which of these is not a primitive data type?
    A) int
    B) double
    C) String
    D) boolean
    Answer: C) String
  9. 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
  10. 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()

  1. Which keyword is used to prevent inheritance in Java?
    A) static
    B) final
    C) const
    D) void
    Answer: B) final
  2. Which of the following is a ternary operator in C?
    A) ? :
    B) ++
    C) &&
    D) <>
    Answer: A) ? :
  3. Which method is used to add an element in a Python list?
    A) insert()
    B) add()
    C) append()
    D) push()
    Answer: C) append()
  4. Which function is used to find square root in C?
    A) sqrt()
    B) square()
    C) power()
    D) root()
    Answer: A) sqrt()
  5. Which one is not a valid access modifier in Java?
    A) private
    B) protected
    C) hidden
    D) public
    Answer: C) hidden
  6. Which of the following is used for file handling in Python?
    A) open()
    B) file()
    C) fopen()
    D) read()
    Answer: A) open()
  7. 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
  8. 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
  9. What is the default value of an uninitialized int in C?
    A) 0
    B) Null
    C) Garbage value
    D) -1
    Answer: C) Garbage value
  10. Which of the following is used to catch exceptions in Java?
    A) try
    B) except
    C) catch
    D) try-catch
    Answer: D) try-catch

  1. 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):
  2. Which of these is a keyword in C++?
    A) variable
    B) return
    C) function
    D) define
    Answer: B) return
  3. Which keyword is used to define a structure in C?
    A) struct
    B) object
    C) class
    D) record
    Answer: A) struct
  4. Which function is used to convert string to integer in Python?
    A) str()
    B) int()
    C) parseInt()
    D) number()
    Answer: B) int()
  5. What is the return type of main() in C?
    A) void
    B) int
    C) char
    D) double
    Answer: B) int
  6. Which of the following is used to create a comment block in C?
    A) //…//
    B)
    C) //
    D) #…#
    Answer: C) //
  7. Which data type is used for decimal numbers in Python?
    A) int
    B) str
    C) float
    D) char
    Answer: C) float
  8. Which function is used to exit a program in C?
    A) return()
    B) quit()
    C) stop()
    D) exit()
    Answer: D) exit()
  9. 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)
  10. Which of these is a relational operator?
    A) =
    B) ==
    C) :=
    D) !==
    Answer: B) ==

  1. What is the result of 4 // 2 in Python?
    A) 2.0
    B) 2
    C) 2.5
    D) 1
    Answer: B) 2
  2. Which function is used to get string length in C?
    A) len()
    B) strlen()
    C) length()
    D) strlength()
    Answer: B) strlen()
  3. Which of these is an IDE for Python?
    A) Eclipse
    B) Turbo C
    C) PyCharm
    D) NetBeans
    Answer: C) PyCharm
  4. Which data type stores only True/False in Python?
    A) bit
    B) int
    C) boolean
    D) bool
    Answer: D) bool
  5. Which of these is used to allocate memory in C++?
    A) malloc
    B) new
    C) calloc
    D) alloc
    Answer: B) new
  6. Which keyword is used to inherit a class in C++?
    A) extends
    B) :
    C) inherits
    D) implements
    Answer: B) :
  7. What is the extension of a compiled Java file?
    A) .java
    B) .exe
    C) .class
    D) .jclass
    Answer: C) .class
  8. Which Python keyword is used for error handling?
    A) try
    B) handle
    C) error
    D) raise
    Answer: A) try
  9. 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
  10. 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)


  1. Which of the following is not a keyword in C?
    A) switch
    B) typedef
    C) class
    D) goto
    Answer: C) class
  2. Which of the following is not a valid variable name in Python?
    A) my_var
    B) _var
    C) 2var
    D) var2
    Answer: C) 2var
  3. Which function is used to read a character in C?
    A) getchar()
    B) readchar()
    C) scanchar()
    D) getch()
    Answer: A) getchar()
  4. Which operator is used to concatenate strings in Python?
    A) +
    B) &
    C) .
    D) *
    Answer: A) +
  5. Which of the following is a logical operator in C?
    A) &&
    B) ++
    C) ::
    D) ?:
    Answer: A) &&
  6. 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
  7. Which of the following is used for inheritance in Java?
    A) extends
    B) inherits
    C) :
    D) base
    Answer: A) extends
  8. 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():
  9. 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())
  10. 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

  1. Which function is used to write output in C++?
    A) print()
    B) write()
    C) cout
    D) echo()
    Answer: C) cout
  2. Which module in Python is used for math functions?
    A) math
    B) calc
    C) numbers
    D) numerical
    Answer: A) math
  3. Which symbol is used for comments in Python?
    A) //
    B) #
    C)
    D) /* */
    Answer: B) #
  4. What will be the output of: 5 == 5 in Python?
    A) True
    B) False
    C) 1
    D) Error
    Answer: A) True
  5. Which access modifier allows access within the same class in Java?
    A) public
    B) private
    C) protected
    D) default
    Answer: B) private
  6. Which keyword is used to define a macro in C?
    A) macro
    B) define
    C) #define
    D) const
    Answer: C) #define
  7. Which one is not a valid C++ data type?
    A) int
    B) float
    C) real
    D) char
    Answer: C) real
  8. 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]
  9. 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
  10. Which of the following is not a valid function in C?
    A) main()
    B) printf()
    C) input()
    D) scanf()
    Answer: C) input()

  1. Which operator is used to raise power in Python?
    A) ^
    B) pow
    C) **
    D) ^^
    Answer: C) **
  2. Which one of the following is used to terminate a statement in C++?
    A) :
    B) ;
    C) .
    D) ,
    Answer: B) ;
  3. Which function is used to get input from user in Python?
    A) scanf()
    B) input()
    C) cin>>
    D) gets()
    Answer: B) input()
  4. Which keyword is used to create a class in C++?
    A) struct
    B) class
    C) object
    D) type
    Answer: B) class
  5. 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]
  6. 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
  7. Which of the following is a mutable data type in Python?
    A) tuple
    B) list
    C) string
    D) int
    Answer: B) list
  8. What is the extension of Python files?
    A) .py
    B) .pt
    C) .python
    D) .pyt
    Answer: A) .py
  9. 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()
  10. 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

  1. What does int x = 10 / 3; store in C?
    A) 3
    B) 3.33
    C) 4
    D) Error
    Answer: A) 3
  2. Which Python data structure is best for key-value pairs?
    A) list
    B) tuple
    C) dict
    D) set
    Answer: C) dict
  3. 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
  4. Which of the following is not allowed in variable names in C?
    A) _
    B) 0-9
    C) space
    D) letters
    Answer: C) space
  5. Which statement is used for conditional execution in Python?
    A) if
    B) when
    C) switch
    D) select
    Answer: A) if
  6. Which is not a valid file mode in Python?
    A) ‘r’
    B) ‘w’
    C) ‘rw’
    D) ‘a’
    Answer: C) ‘rw’
  7. Which keyword is used to handle exceptions in Python?
    A) catch
    B) handle
    C) except
    D) error
    Answer: C) except
  8. Which of the following is a bitwise operator in C?
    A) &&
    B) ||
    C) &
    D) <>
    Answer: C) &
  9. Which function is used to convert a string to float in Python?
    A) float()
    B) str()
    C) double()
    D) convert()
    Answer: A) float()
  10. Which function is used to print something in Python?
    A) echo()
    B) print()
    C) display()
    D) write()
    Answer: B) print()

  1. 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
  2. Which of these is a type of loop?
    A) repeat-until
    B) for
    C) start
    D) case
    Answer: B) for
  3. Which keyword is used to define a constant in C?
    A) const
    B) final
    C) constant
    D) define
    Answer: A) const
  4. What is used to read input from the console in C++?
    A) input()
    B) scanf()
    C) cin
    D) read()
    Answer: C) cin
  5. 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
  6. Which of the following is an OOP principle?
    A) Encapsulation
    B) Looping
    C) Typing
    D) Scanning
    Answer: A) Encapsulation
  7. Which operator is used for not equal in C++?
    A) /=
    B) !=
    C) <>
    D) not=
    Answer: B) !=
  8. Which character is used for newline in Python?
    A) /n
    B) \n
    C) \r
    D) ^n
    Answer: B) \n
  9. 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
  10. 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)


  1. Which of the following is used to start a comment in C++?
    A) /*
    B) //
    C) #
    D) <!–
    Answer: B) //
  2. Which keyword is used to declare a class in Java?
    A) class
    B) Class
    C) struct
    D) object
    Answer: A) class
  3. 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”)
  4. What is the default return type of main() in C?
    A) void
    B) int
    C) float
    D) char
    Answer: B) int
  5. Which symbol is used for address-of operator in C?
    A) *
    B) &
    C) %
    D) @
    Answer: B) &
  6. What will print(2 ** 3) output in Python?
    A) 6
    B) 8
    C) 9
    D) 5
    Answer: B) 8
  7. 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
  8. What will be the output of print(len("Hello")) in Python?
    A) 4
    B) 5
    C) 6
    D) Error
    Answer: B) 5
  9. Which of the following is a valid character constant in C?
    A) “A”
    B) A
    C) ‘A’
    D) ‘A’
    Answer: C) ‘A’
  10. 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

  1. Which of the following is used for decision making in C?
    A) for
    B) while
    C) if
    D) goto
    Answer: C) if
  2. Which of these is not a primitive data type in Java?
    A) int
    B) float
    C) boolean
    D) String
    Answer: D) String
  3. 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)
  4. Which of the following keywords is used to stop a loop in C?
    A) end
    B) break
    C) exit
    D) return
    Answer: B) break
  5. Which operator is used for assignment in all languages?
    A) ==
    B) :=
    C) =
    D) =>
    Answer: C) =
  6. 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
  7. Which operator is used to compare two values in C?
    A) =
    B) :=
    C) ==
    D) =>
    Answer: C) ==
  8. In Java, which of these is not a loop?
    A) for
    B) while
    C) do-while
    D) repeat-until
    Answer: D) repeat-until
  9. Which of the following functions can convert string to integer in Python?
    A) string()
    B) int()
    C) input()
    D) str()
    Answer: B) int()
  10. Which of these is the escape character in C?
    A) /
    B) \
    C) #
    D) %
    Answer: B) \

  1. 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];
  2. Which of these is not a valid loop in Python?
    A) for
    B) while
    C) do
    D) None
    Answer: C) do
  3. Which of these is not a valid Java identifier?
    A) myVar
    B) 2value
    C) _value
    D) $amount
    Answer: B) 2value
  4. 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() {}
  5. Which data type is used to store decimal numbers in Python?
    A) int
    B) str
    C) float
    D) bool
    Answer: C) float
  6. Which function is used to determine the length of a string in C?
    A) size()
    B) len()
    C) length()
    D) strlen()
    Answer: D) strlen()
  7. Which of these is used to comment in Java?
    A) #
    B) //
    C)
    D) —
    Answer: B) //
  8. 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]
  9. Which of these is not a built-in function in C?
    A) printf()
    B) scanf()
    C) input()
    D) gets()
    Answer: C) input()
  10. Which keyword is used to create a method in Java?
    A) method
    B) def
    C) function
    D) void
    Answer: D) void

  1. Which character is used to include headers in C?
    A) &
    B) #
    C) %
    D) @
    Answer: B) #
  2. Which Python keyword is used to handle errors?
    A) error
    B) handle
    C) try
    D) catch
    Answer: C) try
  3. Which data type can hold only True or False?
    A) int
    B) float
    C) bool
    D) char
    Answer: C) bool
  4. Which of the following is a post-increment operator in C++?
    A) ++i
    B) i++
    C) i+=
    D) i=+
    Answer: B) i++
  5. Which is the default access specifier in C++?
    A) private
    B) protected
    C) public
    D) None
    Answer: A) private
  6. Which of these is not a Python loop keyword?
    A) for
    B) while
    C) do
    D) break
    Answer: C) do
  7. Which of the following is not a Python keyword?
    A) lambda
    B) try
    C) then
    D) with
    Answer: C) then
  8. In C, which function is used to find the square root?
    A) sqrt()
    B) root()
    C) sqr()
    D) pow()
    Answer: A) sqrt()
  9. Which keyword is used to inherit a class in C++?
    A) base
    B) public
    C) extend
    D) super
    Answer: B) public
  10. Which of these is used to define a block in Python?
    A) {}
    B) ()
    C) : and indentation
    D) ;
    Answer: C) : and indentation

  1. Which header file includes printf() in C?
    A) stdlib.h
    B) math.h
    C) stdio.h
    D) string.h
    Answer: C) stdio.h
  2. What will type(3.5) return in Python?
    A) int
    B) double
    C) float
    D) str
    Answer: C) float
  3. Which operator is used for modulus in C?
    A) /
    B) //
    C) %
    D) \
    Answer: C) %
  4. Which one is a Python IDE?
    A) Turbo C
    B) Dev C++
    C) PyCharm
    D) Eclipse C
    Answer: C) PyCharm
  5. Which one is used for inheritance in Python?
    A) base
    B) extends
    C) :
    D) (ParentClass)
    Answer: D) (ParentClass)
  6. Which function is used to round numbers in Python?
    A) round()
    B) floor()
    C) ceil()
    D) fix()
    Answer: A) round()
  7. What is None in Python?
    A) A number
    B) A boolean
    C) A special constant
    D) A function
    Answer: C) A special constant
  8. Which function is used to find maximum in Python?
    A) max()
    B) greatest()
    C) top()
    D) highest()
    Answer: A) max()
  9. Which operator is used for logical AND in Python?
    A) &&
    B) and
    C) &
    D) AND
    Answer: B) and
  10. What is the output of print(10 // 3) in Python?
    A) 3.33
    B) 3
    C) 3.0
    D) 4
    Answer: B) 3

SSC / Banking Exam Computer Topics Action
General Awareness (Common) Basic Computer Fundamentals
History & Evolution of Computers
Types of Computers
Computer Hardware & Software
Operating Systems
Memory & Storage Devices
MS Office
Computer Networking
Cyber Security
Programming Basics
Database Management System
Internet & Web Technologies
E-Governance & Digital India
SSC CGL Tier 2 Computer Knowledge Module (Paper 1)
SSC CHSL Computer Awareness Section
SSC Stenographer/MTS Basic Computer Awareness

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
Verified by MonsterInsights