Server Side Programming Articles - Page 2380 of 2650

Print “Hello World” in C/C++ without using header files

Samual Sam
Updated on 26-Jun-2020 08:36:48

814 Views

Generally, we use header files in C/C++ languages to access the built-in functions like int, char, string functions. The function printf() is also a built-in function which is declared in “stdio.h” header file and it is used to print any kind of data on console.Here is an example to print without header files in C language, Exampleint printf(const char *text, ...); int main() {    printf( "Hello World" );    return 0; }OutputHello WorldIn the above program, we printed “Hello World” without using any header file in the program by declaring the printf() function. The declaration of printf() is as ... Read More

Swap two variables in one line in C/C+

Tapas Kumar Ghosh
Updated on 14-Apr-2025 18:23:50

2K+ Views

In C++, swapping two variables means exchanging the values stored in them. There can be multiple ways to implement the swapping using single line statement. In this article, we are going to learn some of the approaches to swap the values. Example Let's consider the following example with input and output scenario: Input: int a = 5; int b = 6; Output: a = 6 b = 5 You can implement swapping of two variable by using the following different ways: Using Arithmetic Operator Using Tuple Using XOR Swap Two Variables Using Arithmetic Operator In ... Read More

Print 1 to 100 in C++, without loop and recursion

Samual Sam
Updated on 26-Jun-2020 08:11:52

965 Views

There are several methods to print numbers without using loops like by using recursive function, goto statement and creating a function outside main() function.Here is an example to print numbers using goto statement in C++ language,Example Live Demo#include using namespace std; int main() {    int count=1;    int x;    cout > x;    PRINT:    cout

What are Wild Pointers in C/C++?

Tapas Kumar Ghosh
Updated on 21-Apr-2025 18:05:33

3K+ Views

In C/C++, a wild pointer is a type of pointer that has not been initialized to a valid memory address. It points to memory that has been deallocated and is called a dangling pointer. The pointer behaves like a wild pointer when it is declared but not initialized. That is why, they point to random memory location. Syntax The basic syntax of initializing wild pointer in C/C++: int *ptr; Example of Wild Pointer In this example, we create a pointer arr that doesn't assign it any memory. Then, it tries to print 5 values from it using a loop. ... Read More

C++ Program to Sum the digits of a given number

Nishu Kumari
Updated on 03-Mar-2025 13:17:07

14K+ Views

The task is to write C++ programs that calculates the sum of the digits of a given number. For example, if the number is 453, the sum of its digits would be 4 + 5 + 3 = 12. To solve this, we will extract each digit from the number and add them together. We will use basic programming concepts such as loops and arithmetic operations to achieve this. In this article, we will show you how to write a C++ program that takes a number as input and sums the digits of that number. Approaches for ... Read More

Implement your own sizeof operator using C++

Tapas Kumar Ghosh
Updated on 21-Apr-2025 18:00:20

986 Views

In C++, the sizeof() operator is a unary operator which is used to calculate the size of any data type. Implementing sizeof() OperatorWe can use the #define directive to implement a macro that copies the behavior of the sizeof() operator for objects, though it will not be the same as the sizeof() operator. Syntax Following is the syntax of C++ macro to implement the sizeof(): #define any_name(object) (char *)(&object+1) - (char *)(&object) Here, any_name : The name you want to give to your own sizeof() operator. Note: The main benefit of using MACROS is defining by once ... Read More

What all is inherited from parent class in C++?

Tapas Kumar Ghosh
Updated on 04-Jun-2025 14:22:42

4K+ Views

In C++, when a class inherits from another class, it inherits all members from parent class, but their accessibility are based on access specifiers. Key Points on What Inherits from Parent Class Following are some points on derived class inherits from its parent: The derived class can inherit data members, member functions of base class. If the data members are public, they can be accessed by derived class, same class and outside the class. If data members are protected, they can be accessed by derived and same ... Read More

How will you print numbers from 1 to 100 without using loop in C?

Tapas Kumar Ghosh
Updated on 21-Apr-2025 18:12:19

4K+ Views

You can print the numbers from 1 to 100 without a loop by using the various methods like recursive function and goto statement that print the list of integers.The following are the approaches to print the numbers from 1 to 100: Using Recursion As we know, recursion is the process of calling the function itself. Here, we use the recursive function to accept an integer and set the iteration of plus 1 without the logic of loop and get the expected outcome. Example In this example, we use an if statement to check whether the given integer is less than ... Read More

(limits.h) in C/C++

Vivek Verma
Updated on 28-Aug-2025 16:45:39

1K+ Views

Both and "limits.h" are header files in C and C++ that are used to define constants related to data type limits. Header files are usually created with a .h extension and are used to declare functions, variables, and other entities without having a main() function. You can also create custom header files in C and C++. The header file is specific to the C++ language, whereas "limits.h" belongs to the C language. Let's discuss them one by one with the help of a suitable example to understand them and their uses in a program in a better way: ... Read More

isgraph() C library function

karthikeya Boyini
Updated on 26-Jun-2020 08:17:52

155 Views

The function isgraph() is used to check that the passed character has a graphical representation or not. It is declared in “ctype.h” header file.Here is the syntax of isgraph() in C language, int isgraph(int char);Here is an example of isgraph() in C language, Example Live Demo#include #include int main() {    int a = '';    int b = '8';    int c = 's';    if(isgraph(a))    printf("The character has graphical representation");    else    printf("The character isn’t having graphical representation");    if(isgraph(b))    printf("The character has graphical representation");    else    printf("The character isn’t having graphical representation");    if(isgraph(c)) ... Read More

Advertisements