Computer Networks and C Programming Questions and Answers

Computer Networks

Fill in the Blanks

  1. The hostname command is used to display the name of the computer.
  2. The length of an IPv4 and an IPv6 address is 32 bits (4 bytes) and 128 bits (16 bytes) respectively.
  3. An access point is used to connect to a wireless network.
  4. The ping command is used to verify the connectivity between two computers.
  5. HTTPS transfers encrypted data.

Multiple Choice Questions

  1. Which device is required to connect multiple heterogeneous networks?
    a) hub
    b) Switch
    c) Router
    d) Access Point
    Ans: Router
  2. Which is the largest type of computer network?
    a) PAN
    b) LAN
    c) MAN
    d) WAN
    Ans: WAN
  3. Which protocol transfers encrypted data instead of plain data?
    a) HTTP
    b) HTTPS
    c) FTP
    d) SMTP
    Ans: HTTPS
  4. How many bytes are reserved for OUI in a MAC address?
    a) 3
    b) 8
    c) 24
    d) 12
    Ans: 24 (3 bytes)
  5. An IP address can be automatically assigned if the network is connected with a:
    a) Access Point
    b) Mail Server
    c) Web Server
    d) DHCP Server
    Ans: DHCP Server

Short Answer Questions

  1. Mention the name of components required to set up a MAN network. Draw a block diagram of a MAN network, labeling the name of each component. (Hint: A MAN is a connection of multiple LANs).
    Ans. A MAN may use a local exchange carrier (LEC) to provide the connections between LANs and may connect to an internet exchange point for high-speed communication between the MAN and the public internet.
  2. Why shouldn’t a hostname be used to identify a computer in a computer network?
    Ans. Hostnames may not be unique. There is a possibility that two or more computers in a computer network may have the same hostname. For this reason, hostnames should not be used to identify a computer in a computer network.
  3. Give five examples of valid and five examples of invalid IPv4 addresses.
    Ans. A valid IPv4 address must be in the form of A.B.C.D, where A, B, C, and D are numbers from 0-255.
    Valid IPv4 Addresses:
    • 172.16.254.2
    • 192.0.2.146
    • 192.168.2.254
    • 165.254.11.135
    • 168.14.204.3
    Invalid IPv4 Addresses:
    • 0.168.120.26 (Any address that begins with 0 is generally considered invalid in the context of classful addressing, though it might represent a valid host address in some specific contexts.)
    • 192.16.152.260 (Any address with a number above 255 is invalid).
    • 192.16.152.250.12 (Any address that has more than three dots is invalid).
    • 255.255.255.255 (This address is reserved for broadcasts and cannot be assigned to a host.)
    • 2001.162 (A valid IPv4 address must consist of four octets).
  4. Can we compare HTTP and FTP protocols? Mention their functionality.
    Ans. Comparison between HTTP and FTP:
    ParameterHTTPFTP
    Full-formHyper Text Transfer ProtocolFile Transfer Protocol
    MeaningA set of rules for transferring web pages over the internet.A set of rules for uploading and downloading files between a server and a client.
    UsesProviding web pages from a web server to a web browser. URLs begin with “http://” or “https://”.Downloading and uploading files between a server and a client. URLs begin with “ftp://”.
  5. How many 16-port switches are required to connect 31 computers in a network?
    Ans. To connect 31 computers, you would need two 16-port switches, or one switch with more than 31 ports.

C Programming

Loops

  1. Why do we use loops in C programs?
    Ans: Loops are used to repeat the same code for a finite number of times.
  2. Do we need to use only one type of loop in a C program? Justify your answer by writing a C program.
    Ans: No, we can use all types of loops in a C program. C has three different types of loops: for, do…while, and while. A C program can be written using all three types of loops.
  3. What will happen if we write a while loop with 1 in place of the condition? Try it in a simple C program. Hint: while (1) { printf("We must raise our voice against corruption \n"); }
    Ans: If we write a while loop with 1 (or any other non-zero value) in place of the condition, the loop will execute forever because the condition will always be true, creating an infinite loop.
  4. Name different portions of a for loop. Can we put more than one statement within a portion?
    Ans: The three portions of a for loop are:
    1. Initialization expression
    2. Condition/test expression
    3. Update expression
    Yes, we can put more than one statement within each portion by separating them with commas.
  5. Answer with True or False.
    1. If the condition of the while loop is false, the control comes to the second statement inside the loop. FALSE
    2. We can use at most three loops in a single C program. FALSE
    3. The statement inside the do-while loop executes at least once, even if the condition is false. TRUE
    4. Only the first statement inside the do-while loop executes when the condition is false. FALSE
    5. In a do-while loop, the condition is written at the end of the loop. TRUE

Arrays

  1. Define Array? Why do we use arrays in computer programs?
    Ans: An array is a collection of similar data items stored in contiguous memory locations. Each data item is called an element, accessible by its index (relative position). We use arrays to store multiple values in a single variable, instead of declaring separate variables for each value.
  2. Can we store both integer and float types of data in a single array? Demonstrate this by writing a simple C program?
    Ans: No, we cannot store both integer and float types of data in a single array in C. Arrays are designed to hold elements of the same data type.
  3. Write the indices of the first and last element of the following array declaration:
    char city[7] = {'S','I','L','C','H','A','R'};
    Ans: The index of the first element (‘S’) is 0, and the index of the last element (‘R’) is 6.