Ask Programiz - Human Support for Coding Beginners

Explore questions from fellow beginners answered by our human experts. Have some doubts about coding fundamentals? Enroll in our course and get personalized help right within your lessons.

  • All
  • Python
  • C
  • Java
  • CPP
  • SQL
  • JS
  • HTML
  • CSS
Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hi M Idrees Gul,

It usually will not cause an error. The " " is just a space, used to make the output readable.

Without it, the text prints back to back:

cout << "Hey." << "Are you enjoying the course?";

Output:
Hey.Are you enjoying the course?

With a space in between:

cout << "Hey." << " " << "Are you enjoying the course?";

Output:
Hey. Are you enjoying the course?

So " " is not required for the program to run, it is just for nicer output.

If you have more questions, I am 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 Harish Hansda,

No, Java class names cannot contain spaces. A class name must be a single identifier.

If you want multiple words, write them together using CamelCase, like this:

class MyFirstClass {
}

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

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

Hi Yichao,

In Java, length for an array is a field (a value stored in the array), not a method. That is why you write it without parentheses:

int[] nums = {1, 2, 3};
System.out.println(nums.length);  // 3

Parentheses are only used for methods. For example, strings use a method:

String s = "abc";
System.out.println(s.length());  // 3

So the simple rule is: arrays use length, strings use length().

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

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

Hi Rana Adnan,

Yes, the element you want to position absolutely must be inside the parent in the HTML.

But one more important thing: it will be positioned relative to the nearest parent that has a position set like relative, absolute, or fixed. Most of the time we set the parent to position: relative; so the child stays inside that box.

Example:

.parent { position: relative; }
.child  { position: absolute; top: 0; right: 0; }

If no parent has a position set, the absolute element is positioned relative to the page (the viewport/document), which is why it can jump to a weird place.

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

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

Hi s j,

In C, a string needs one extra character at the end called the null terminator '\0' to mark where the text ends.

So char name[20] has 20 slots total:

  • up to 19 slots for the characters you type

  • 1 slot for '\0'

That is why you can only store 19 normal characters, even though the array size is 20.

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

Hi Revathi Kasireddy,

print is not a variable. It is a built-in function that shows output on the screen.

A variable is something like greeting that stores a value:

greeting = "Merry Christmas"
print(greeting)   # prints the value inside greeting

So print() displays a value, and the variable is what holds the value.

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

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

Hi Tanvi,

We use #include because it gives your program access to standard input and output functions like printf() and scanf().

Example:

#include 

int main() {
    printf("Hello");
    return 0;
}

Without stdio.h, the compiler may not recognize printf() properly.

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

Hi 王宇杰,

In Python, the / operator always returns a float, so 25 / 5 becomes 5.0 even though it is a whole number.

If you want an integer result, use //:

print(25 // 5)  # 5

If you have more questions, I am 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 there! That's a great and very common question when starting to learn about variables in C programming.

To answer your question: You do not need to use int again to change the age variable and print it.

The int keyword is only used when you first declare a variable to specify that the variable is of type integer. Once you've declared the variable, you can change its value without redeclaring its type.

In your example:

#include 

int main() {

    // Create an int variable and print it 
    int age = 25; // Declare and initialize the variable
    printf("%d ", age);

    // Assign a new value and print it
    age = 31; // Change the value of the already declared variable
    printf("%d", age);

    return 0;
}

Initially, you declare int age = 25; to create an integer variable age and set its value to 25. After that, you can simply change the value using age = 31; without using int again. The printf function can then print the updated value without any further declarations.

Hope this helps! Feel free to ask if you have any more questions. 😊

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

Hi Istvan,

#include adds the iostream library so your C++ program can do input and output, like printing to the screen and reading from the keyboard.

It lets you use things like cout and cin, for example:

#include 
using namespace std;

int main() {
    cout << "Hello";
    return 0;
}

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

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