Abhay Jajodia's profileExpert

Abhay Jajodia

Answered 166 questions


About

Designer by day, web developer by night, and a full-time tech + gaming nerd in between. I'm always learning, always curious — chasing life's bonus levels, secret achievements, and power-ups like it's one big epic quest.

Answered by Abhay Jajodia
Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hi Harkirat, in C, isdigit() returns 0 for false and any non-zero number for true, and the exact “true” number can be different depending on the system. So 2048 still just means true.

printf("%d\n", isdigit('8')); // non-zero means true (could be 2048)

If you have more questions, I am here to help.

C
This question was asked as part of the Learn C Programming course.
Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Good question — both approaches will give you the same result: the string "5.5". But there’s a subtle difference in flexibility.

In the first version:

number_str = str(5.5)

You're hardcoding the value 5.5. This works fine, but it's less reusable.

In the second version:

number = 5.5  
number_str = str(number)

You're converting the value stored in the variable number to a string. This makes your code more flexible — if the value of number changes later, you don’t need to update multiple places in your code.

So while both are technically correct, using the variable is generally the better practice.

Python
This question was asked as part of the Getting started with Python course.
Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hi Rishabh,

Good question — I see where the confusion is coming from.

Your query is counting how many distinct brands exist in the filtered data. Since you're filtering for ByteCore and ZapTech, there are clearly two distinct brands. So COUNT(DISTINCT brand) should return 2 — and it does.

But if you're getting 3 as the result, then the issue might be that you’re actually counting distinct product names, not brands.

If your intention is to count unique products under those brands, you should change the query to this:

SELECT COUNT(DISTINCT name) AS distinct_product  
FROM Products  
WHERE brand = 'ByteCore' OR brand = 'ZapTech';

This will count the number of different product names from those two brands — for example: keyboard, mouse, and headphone — which would give you 3.

So check what exactly you’re trying to count: brands or product names. That makes all the difference.

If you have more questions, I’m here to help.

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

Hi Sanskriti,

Great question. A function doesn’t need a return statement to run, but whether or not you use it depends on what the function is supposed to do.

If a function is only doing a task (like printing something or updating a value) and isn’t meant to give anything back, you don’t need a return value — that's when you define it with void.

But if you want the function to send a result back to the place it was called from, you need a return statement.

Here’s an example:

int add(int a, int b) {
    return a + b;
}

int main() {
    int result = add(3, 5);
    printf("%d", result);  // Output: 8
    return 0;
}

The add function returns the sum of two numbers. That return value is stored in result and printed. Without return, the function wouldn’t send anything back, and you'd have nothing to work with.

Also, if you declare a function to return a value (like int, float, etc.) but forget to use return, you might get incorrect results or even undefined behavior.

So in short:

  • Use return when you need a result from the function.

  • Skip it if the function is just doing something and doesn’t need to report back.

If you have more questions, I’m here to help.

C
This question was asked as part of the Learn C Programming course.
Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hi Mārtiņš,

Variables are called temporary because they only exist while the program is running. They're used to store values in memory that your program needs at that moment — like numbers, strings, or results from calculations.

Here’s a simple example:

int main() {
    int score = 0;
    score += 10;
    printf("Current Score: %d\n", score);
    return 0;
}

In this code, the variable score holds a value temporarily. Once the program finishes running, the data stored in score is gone — unless you explicitly save it somewhere, like a file or database.

So to sum up: variables help your program work with data during execution, but they don't keep that data permanently.

If you have more questions, I’m here to help.

C
This question was asked as part of the Learn C Programming course.
Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hi Archana,

We use increment (++) and decrement (--) operators in C++ to quickly increase or decrease a variable's value by 1. They're mainly used for:

  1. Simpler code
    Instead of writing i = i + 1, you can just write i++. It’s shorter and easier to read.

  2. Looping
    These operators are commonly used in loops. For example:

    for (int i = 0; i < 5; i++) {
        cout << i << " ";
    }
    

    This loop prints: 0 1 2 3 4

  3. Prefix vs Postfix

    • ++i (prefix) increases the value before it’s used

    • i++ (postfix) uses the value first, then increases it

    Example:

    int i = 5;
    cout << ++i; // Outputs 6  
    cout << i++; // Outputs 6, then i becomes 7
    

Both forms are useful depending on when you want the increment or decrement to happen.

If you have more questions, I’m here to help.

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

Hi Hao,

No problem — the while loop can be a bit confusing at first, but it’s actually pretty straightforward once you get the pattern.

A while loop runs a block of code over and over as long as a condition is true.

Here’s a simple example:

count = 1

while count <= 3:
    print("I am inside a loop.")
    print("Looping is interesting.")
    count = count + 1

print("OUTSIDE THE LOOP")

What’s happening here:

  1. count starts at 1

  2. The loop checks: is count <= 3?

    • If yes, it runs the code inside the loop

    • Then it increases count by 1

  3. It checks the condition again

  4. Once count becomes 4, the condition is no longer true, and the loop stops

Output:

I am inside a loop.
Looping is interesting.
I am inside a loop.
Looping is interesting.
I am inside a loop.
Looping is interesting.
OUTSIDE THE LOOP

So the loop runs 3 times, and then the program moves on.

The key is: if you forget to update the variable (count = count + 1), the condition might always be true — and the loop would run forever.

Let me know if anything's still unclear — I’m here to help.

Python
This question was asked as part of the Getting started with Python course.
Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hi Pratik,

Great question — this part can be a little tricky at first.

In Bubble Sort, we compare and swap adjacent elements to move the largest value to the end of the array in each pass. That’s why we don’t need the outer loop to run through the entire array.

Let’s say the array has n elements. After the first full pass, the largest element is already in its correct place at the end. So in the next pass, we only need to go up to n - 2. That’s why the outer loop runs only n - 1 times — like this:

for (int i = 0; i < arr.size() - 1; ++i)

After each pass, one more element is sorted and doesn’t need to be touched again. So we reduce the number of iterations in the outer loop by 1 compared to the total size of the array.

This helps avoid unnecessary comparisons and makes the algorithm more efficient.

If you have more questions, I’m here to help.

C++
This question was asked as part of the DSA with C++ course.
Donald Coates
PRO
last year
Donaldcountry asked
Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hi there! JSON is a common way to format and exchange data, especially when you're working on applications that involve the web, like APIs.

JSON, which stands for JavaScript Object Notation, is a lightweight data interchange format that's easy for humans to read and write, and easy for machines to parse and generate. It consists of data represented as key-value pairs, much like a Python dictionary. Here's a simple example:

{
  "name": "Alice",
  "age": 25,
  "isStudent": false
}

In the above JSON snippet, there's a key for "name" with a value of "Alice", a key for "age" with a numeric value of 25, and "isStudent" with a boolean value of false. JSON is widely used to send data to and from web servers; when a server responds to a request, it might send data formatted like this.

Hope this helps you understand JSON! Feel free to reach out if you want to know more or have other questions.

Python
This question was asked as part of the Getting started with Python course.
Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hi Elijah,

Yes, exactly. In C++, when you declare multiple variables on the same line, they all have to be the same type. So if you're declaring int age, id;, both variables are integers.

This is mostly for convenience and cleaner code when you're working with variables of the same type. But if the variables are different types — like an int for age and a string for name — then you'd declare them separately:

int age = 24;
string name = "John";

So grouping variables on one line only works when their data type is the same.

If you have more questions, I’m here to help.

C++
This question was asked as part of the Learn C++ Basics course.