WorksheetsSGA Quiz
Total questions: 20
Worksheet time: 13mins
What is the purpose of a function in Python?
The purpose of a function in Python is to encapsulate code for reuse and improve code organization.
To execute code only once during a program's lifetime
To create variables in Python
To define classes in Python
What is the difference between a function and a method?
A method can be called without an object; a function cannot.
A function is independent; a method is associated with an object.
A function is always part of a class; a method can exist independently.
Functions and methods are the same and have no differences.
How do you read the entire content of a file?
Use 'open(filename) as file: content = file.read()' in Python.
Read the file using 'file.get_contents(filename)' in Python.
Use 'file.read_all(filename)' to read the entire file.
Use 'with open(filename, 'r') as file: content = file.read()' in Python.
How can you handle exceptions in Python?
Ignore exceptions and continue execution without handling them.
Use print statements to debug exceptions in Python.
Use try-except blocks to handle exceptions in Python.
Use if-else statements to handle exceptions in Python.
What is the purpose of the 'try' and 'except' blocks?
To define functions and methods in Python.
The purpose of 'try' and 'except' blocks is to handle exceptions and errors in a controlled manner.
To declare variables and constants in a program.
To create loops and iterations in code.
What are the basic data types in C?
int, float, double, char, void
array
string
boolean
What is the size of an int data type in C?
8 bytes
2 bytes
4 bytes
16 bytes
How do you write a for loop in C?
for(i = 0; i < n; i++) { // code }
for(int i = 0; i < n; i++) { code to execute }
for(int i = 0; i < n; i++) { // code to execute }
for(int i = 0; i < n; i++) // code to execute
What is a pointer in C?
A pointer is a variable that stores a string in C.
A pointer is a type of function in C.
A pointer is a variable that holds the address of another variable in C.
A pointer is a constant value in C.
How do you free dynamically allocated memory?
Call 'clear(pointer)' to release memory allocated with malloc/calloc/realloc and 'destroy pointer' for new.
Invoke 'release(pointer)' for malloc/calloc/realloc and 'freeup pointer' for new.
Use 'dispose(pointer)' for malloc/calloc/realloc and 'remove pointer' for new.
Use 'free(pointer)' for malloc/calloc/realloc and 'delete pointer' for new.
What is the purpose of the 'fclose' function?
To delete an open file stream.
To read data from a file stream.
To close an open file stream.
To create a new file stream.
How do you write to a file in C?
Use close() to write data and open a file.
Use read() to open a file and write directly to it.
Call fwrite() to write data without opening a file.
Use fopen() to open a file, fprintf() or fputs() to write, and fclose() to close the file.
What function is used to read from a file?
readFile()
getFile()
open()
loadFile()
What is a socket in Java?
A socket in Java is a type of data structure.
A socket in Java is an endpoint for communication between two machines.
A socket in Java is used for storing files.
A socket in Java is a graphical user interface component.
Explain the difference between TCP and UDP.
TCP is reliable and connection-oriented, while UDP is faster and connectionless.
TCP is connectionless and has lower latency than UDP.
UDP guarantees delivery of packets, while TCP does not.
TCP is faster and connection-oriented, while UDP is reliable and connectionless.
How does a client-server architecture work?
Clients store all data locally without any server interaction.
Clients directly communicate with each other without a server.
The server sends requests to multiple clients simultaneously.
A client-server architecture works by having clients send requests to a server, which processes the requests and returns responses.
What is the purpose of the transport layer in the TCP/IP model?
To establish physical connections between devices.
To manage network routing and addressing.
To provide reliable data transfer and communication between applications.
To encrypt data for secure transmission.
Describe how to create a simple TCP server in Java.
Use DatagramSocket for UDP communication
Create a TCP server using ServerSocket, accept connections in a loop, and handle client communication with InputStream and OutputStream.
Implement a web server using HttpServer
Create a GUI application for client-server interaction
Describe how to create a simple TCP server in Java.
Use DatagramSocket for UDP communication
Create a TCP server using ServerSocket, accept connections in a loop, and handle client communication with InputStream and OutputStream.
Implement a web server using HttpServer
Create a GUI application for client-server interaction
Explain the concept of port numbers in networking.
Port numbers are used to identify specific processes or services on a networked device.
Port numbers are only relevant for wireless networks.
Port numbers are used to encrypt data during transmission.
Port numbers are physical connectors on a network device.
