Data Types: Basic Data Types Numeric Types Integer types (byte, short, int, long) Type Bits Bytes Notes Range byte 8 1 Automatically promotes to int during operations -128 to +127 short 16 2 Cannot convert directly to byte, promotes to int in calculations -32768 to +32767 int 32 4 Default integer ty...
Capturing User Input The input() function pauses execution to accept data from the console. It always evaluates to a string, regardless of what the user types. user_data = input("Enter your preferred programming language: ") print(user_data, type(user_data)) To perform mathematical operations on use...
1. Comments Java supports three types of comments: Single-line: // comment text Multi-line: /* comment text */ Documentation: /** comment text */ — used for generating API documentation. 2. Keywords Keywords are reserved words with predefined meanings in Java and cannot be used as identifiers (e.g.,...
Introduction I once had an embarrassing moment while trying to extract the current year. I wrote code like this: new Date().getFullYear() At that moment, I felt uncertain because I wasn't sure whether the . operator or the new keyword executes first. I quickly tested it in the console and—phew—no er...
C++ offers a rich set of built-in operators to various computational tasks including arithmetic, logical, bitwise, and relational operations. A powerful feature allows these symbols to be redefined for user-defined types, enhancing readability and intuitive usage. Standard Operator Categories Arithm...
Binary Operators Binary operators require two operands for evaluation. Multiplication (*) #include <stdio.h> int main(void) { int val = 5; printf("%d\n", val * val); return 0; } Division (/) Integer division truncates fractional parts. #include <stdio.h> int main(void) { float...
Arithmetic Operators C language provides several arithmetic operators for performing mathematical operations on variables: + - * / % All operators except % can work with both integers and floating-point numbers. For the / operator, if both operands are integers, integer division is performed. If at...
1. Program and User Interaction 1.1 What is User Interaction? User interaction refers to the process where a user inputs data into a computer, and the computer prints/outputs the results. 1.2 Why User Interaction? To enable computers to communicate with users like humans do. For example, withdrawing...
The & operator serves distinct purposes in C and C++ programming languages, with both shared functionality and language-specific features. Shared Functionality Address-of Opertaor: Both languages use & to obtain a variable's memory address Example (works in both): int value = 8; int *address...
1. Core Operator Concepts What is an Operator? An operator is a symbol representing a computational or logical operation, such as +, -, *, /. Operand Count Classification Operators are grouped by the number of required operands: Unary operators: Require exactly one operand, e.g., ++, --, & Binar...