Programming Basics Questions Answered

Some basic questions related to the programming that arises from time to time by different people. Here are some answers related to some of those major questions. In the time being the programming is becoming a common ground where specialists from any sector should go through some kind of basic programming skills to make the work easier especially with the aid of the latest IT-based technology

Why do you think we need programming languages even if we have software to do a job?

Programming language is basically used to automate, maintain, assemble, measure, and interpret the processing of the data and information. Although we have software to carry out a certain task, new efficient and evolving software can be designed through the use of programming language.

What is the difference between a variable and a constant?

  • A constant does not change its value over time. 
  • A variable changes its value dependent on the equation.
  • Constants usually represent the known values in an equation, expression, or programming language.
  • Variables, on the other hand, represent unknown values.

Every programming language has reserved words. What are they? Give examples.

In a programming language, a reserved word is a word that cannot be used as an identifier, such as the name of a variable, function, or label. It is reserved from use and may have no meaning. For example, in R the reserved words are – If, else, repeat, while.

What happens if we use keywords to declare a variable?

You cannot use keywords as variable names. It's because keywords have predefined meanings.

Write what you know about a function.

Functions are self-containing modules of code that accomplish a specific task. Functions usually take data, process it, and return a result. Once a function is written, it can be used over and over again.

Write what you know about a function.

Functions are self-containing modules of code that accomplish a specific task. Functions usually take data, process it, and return a result. Once a function is written, it can be used over and over again.

What do you understand by loops? Briefly explain the various types of loops.

A loop is a programming structure that repeats a sequence of instructions until a specific condition is met. Loop is used to cycle through values, add sums of numbers, repeat functions, and many other things.

while loop: 

  • Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body.

for loop: 

  • Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.

do...while loop: 

  • It is more like a while statement, except that it tests the condition at the end of the loop body.

nested loops: 

  • You can use one or more loops inside any other while, for, or do..while loop.

 Please explain the operators.

Programming Basics Questions Answered
Different Programming Languages

An operator in a programming language is a symbol that tells the compiler or interpreter to perform the specific mathematical, relational, or logical operation and produce the final result. They are a special type of function, that takes one or more arguments and produces a new value. For example addition (+), subtraction (-), multiplication (*), etc., are all operators. Operators are used to performing various operations on variables and constants.

What do you mean by debugging?

Debugging means locating bugs (faults) in programs and then removing them. In the entire process of the program, development errors may occur at various stages and efforts to detect and remove them may also be made at various stages.

Write the type of the following:

a.    3= integer   

b.    3.5 = numerics          

c.     a = variable   

d.     ‘a’= string     

e.     ‘abc’= string

What is the difference between a++ and ++a?

++a is the pre-increment operator and a++ is the post-increment operator serving the same purpose somehow.

What is the difference between matrix and array?

  • An "array" is a general way of arranging data.
  • A "matrix" is a two-dimensional array that is taken to represent and store the values in the mathematical structure. 

What do you get when you do the following in general programming?

  • 2+2 (=4)    
  • ‘2’+2  (=22)    
  • ‘2’+’2’  (=22)    
  • ‘2’- ‘2’ (=0)

Note: The variable declared outside of a function of a block is called a global variable.

How do you determine a position of a word in a string using programming language? Give example.

You can use the in operator or the string's find method to check if a string contains another string. The in operator returns True if the substring exists in the string. Otherwise, it returns False. The find method returns the index of the beginning of the substring if found, otherwise, -1 is returned.

Example in C

  • size_t pos;
  • if((pos = str.find(chi)) != string::npos) cout << pos;
  • else count << "Not found";

How can you reverse the string? Write a step.

strrev() function

The strrev() function is used to reverse the given string.

Example in Java

  • public class StringFormatter {
  • public static String reverseString(String str){
  • StringBuilder sb=new StringBuilder(str);
  • sb.reverse();
  • return sb.toString();
  • }
  • }