Kelish Rai's profileExpert

Kelish Rai

Technical Content Writer @Programiz

Answered 89 questions


About

Hi, I'm Kelish, Technical Content Writer at Programiz. I break down complex programming concepts and turn them into easy-to-understand articles, tutorials, and courses. I'm also a developer at heart—I love solving coding problems, exploring algorithms, and staying updated with the latest tech stuff. If I'm not writing content, there's a good chance I'm working on a side project.

Answered by Kelish Rai
Kelish Rai
Expert
last year
Kelish Rai answered

In the code:

#include 
using namespace std;

int main() {

    // create a variable
    double number = 83.13;

    // create a pointer variable
    double* pt;

    // assign address to pointer
    pt = &number;
  
    // print pointer pt
    cout << pt;
  
    return 0;
}

The reason the pointer needs to be a double* is that the variable number is of type double.

In C++, the type of a pointer should always match the type of the variable it points to. So if number were an int, then the pointer should also be an int*.

Here's a quick comparison to help make it clearer:

int a = 5;
int* ptr1 = &a;    // OK: both are int

double b = 6.2;
double* ptr2 = &b;    // OK: both are double

double* wrongPtr = &a;    // Not OK: types don’t match (int vs double)

Using the correct pointer type ensures that the program knows how much memory to access and interpret properly. For instance, a double typically uses more bytes than an int, and a mismatch can lead to unexpected behavior.

C++
This question was asked as part of the Learn C++ Basics course.
Kelish Rai
Expert
last year
Kelish Rai answered

It's not mandatory to know HTML or CSS before getting started with JavaScript.

JavaScript is a versatile language — it’s used for everything from making web pages interactive to building servers, mobile apps, and even games. So if you're learning it for general programming purposes (like game development or backend work), you can absolutely start without knowing any HTML or CSS.

That said, if your goal is to build websites or web applications, having a basic understanding of HTML and CSS will definitely make things easier.

  • HTML provides the structure of a webpage (like headings, paragraphs, images).

  • CSS handles the styling (like colors, fonts, layouts).

  • JavaScript adds interactivity (like responding to clicks, form submissions, animations).

Since JavaScript often works closely with HTML and CSS in web development, knowing a little bit about them will help you understand where and how to apply JavaScript effectively.

JS
This question was asked as part of the Learn JavaScript Basics course.
Kelish Rai
Expert
last year
Kelish Rai answered

I agree that all the names listed in the good and bad variable name examples are valid options for C++ programs.

However, when defining good variable names, the goal is to choose names that are both easy to understand and easy to work with.

For example, it’s much clearer to understand a variable named salary than one named s. Similarly, age is much easier to use and comprehend than something like aGekv2, which doesn’t really convey any meaning.

In short, good variable names should be straightforward, intuitive, and consistent.

C++
This question was asked as part of the Learn C++ Basics course.
Kelish Rai
Expert
last year
Kelish Rai answered

In SQL, wildcards like % and _ are mainly used with the LIKE operator inside a WHERE clause to perform pattern matching and filter results.

Without the WHERE clause, wildcards don't really have any effect—because there's no condition to apply them to. Their purpose is to match values against a pattern, and that only happens when you're telling SQL what to search for.

For example:

SELECT * FROM customers
WHERE name LIKE 'A%';

This query returns all customers whose names start with the letter "A". The % wildcard matches any number of characters after "A".

Without the WHERE clause:

SELECT * FROM customers;

You're simply selecting everything—no pattern-matching is happening here, even if wildcards exist elsewhere (e.g., in a computed column or subquery, but those are more advanced cases).

So, to answer simply: wildcards are useful only when combined with LIKE (or sometimes NOT LIKE) inside a WHERE clause, where they serve their purpose of filtering based on patterns.

SQL
This question was asked as part of the Learn SQL Basics course.
Kelish Rai
Expert
last year
Kelish Rai answered

While both overflow: hidden; and height: auto; are related to content overflow, there’s an important difference between them.

Let’s start with overflow: hidden;.

Imagine we have something like this:

div {
  height: 140px;
  overflow: hidden;
}

In this case, the content inside the div might be taller than 140px. However, because we've set a fixed height of 140px, the div itself stays at that height. By using overflow: hidden;, any content that exceeds the boundary of the div is simply hidden from view—it’s cut off and not shown.

On the other hand, when you use height: auto;, the height of the div adjusts based on its content:

div {
  height: auto;
}

This way, if the content inside the div grows or shrinks, the height of the div also grows or shrinks accordingly. No content is hidden, and everything is visible.

Since the div expands to fit the content, there's no need for overflow: hidden;.

CSS
This question was asked as part of the Learn CSS course.
Kelish Rai
Expert
last year
Kelish Rai answered

That's right. When you provide three values to the padding property, the first value applies to the top padding, the second value to the left and right (sides), and the third value to the bottom padding.

You can think of it like this:

padding: top sides bottom;

So, in the example:

padding: 10px 30px 20px;

It will apply:

  • 10px to the top,

  • 30px to both the left and right sides, and

  • 20px to the bottom.

Feel free to ask if you have more questions—I'm happy to help.

CSS
This question was asked as part of the Learn CSS course.
Kelish Rai
Expert
last year
Kelish Rai answered

In this code:

# Function definition
def get_product(number1, number2):
    result = number1 * number2
    return result

# Get integer inputs from the user
n1 = int(input("Enter an integer: "))
n2 = int(input("Enter another integer: "))

# Get the total
total = get_product(n1, n2)

# Print the total
print(total)

This line is where the get_product() function is called:

total = get_product(n1,n2)

Here’s what’s happening: we're calling get_product() and passing it two arguments, n1 and n2. The function then runs, calculates the product, and returns a value. That returned value is what gets stored in the variable total.

Now let’s take another look at the function itself:

def get_product(n1,n2):
    result = n1*n2
    return result

The line return result means the function will send back the value stored in result to wherever the function was called.

Without the return statement, the function would still calculate n1 * n2 and store it in result, but nothing would be passed back to the outside—so the rest of your code wouldn’t have access to the answer.

Note: The return statement is important because it allows you to take the result of a function and use it later in your program. For example, you could use the returned value in further calculations or display it.

Python
This question was asked as part of the Getting started with Python course.
Avelile Khwele
last year
Avelilecountry asked
Kelish Rai
Expert
last year
Kelish Rai answered

In this code:

#include 

char* greet() {
    return "Hello";
}

int main() {
    printf("%s Mia\n", greet());
    printf("Next statement");

    return   0;
}

%s is a format specifier used for strings. That means when the program runs, %s is replaced by whatever the greet() function returns.

Since greet() returns the text "Hello", that text takes the place of %s, so the output becomes:

Hello Mia

If you've seen format specifiers like %d (for integers) or %f (for floating-point numbers), %s works the same way—it's just specifically used to print strings.

Here's a closer look at what this line is doing:

printf("%s Mia\n", greet());

This tells the program: Print a string (%s), followed by the word “Mia” and a newline. Replace %s with the return value from the greet() function.

So effectively, it behaves like:

printf("Hello Mia\n");

Also, the greet() function is written as:

char* greet() {
    return "Hello";
}

It returns a string (specifically, a pointer to the string "Hello"), which is exactly what %s expects in a printf call.

C
This question was asked as part of the Learn Recursion With C course.
Kelish Rai
Expert
last year
Kelish Rai answered

Yes, you can write as many single-line comments as you want in your program.

Comments are simply there to help us understand the code better—they're not read or executed by the computer. So whether you're explaining a complex line or just noting something down for later, using many single-line comments is completely fine.

Here’s a quick example:

// This program prints a number
#include 

int main() {
    int number = 5; // Declare a variable
    printf("%d", number); // Print the value of number
    return 0;
}

Each // comment is considered a single-line comment, and you can write one before or after a line of code, or even leave full lines just for comments.

You can also use multi-line comments if you want to write longer explanations that span across several lines. In C, multi-line comments are written like this:

/* This is a multi-line comment.
   You can write across multiple lines,
   and it ends with a closing */
C
This question was asked as part of the Learn C Programming course.
Kelish Rai
Expert
last year
Kelish Rai answered

In this code:

print("Hello, World!")

The different colors you see are there because of something called syntax highlighting. It's a feature provided by code editors to make your code easier to read and understand.

For example, in the above code:

  • print is shown in purple because it's a feature provided by Python itself.

  • "Hello, World!" is shown in green because it's a value.

These colors are only for you—the programmer—to help you quickly recognize different parts of your code.

When you run the program, the computer doesn't notice these colors. It just follows the instructions we've written.

Hope this clears things up. Let me know if you have more questions.

Python
This question was asked as part of the Getting started with Python course.