Skip to content

Programming Articles

  • HOME
  • Python
  • JavaScript
  • C/C++
  • Java
  • Terms & Conditions and Privacy Policy
  • About US
Main Menu

C/C++

Articles related to C and C++ programming languages.

C/C++ / Linux

How to profile C++ code running on Linux?

If your goal is to use a profiler, use one of the suggested ones. However, if you’re in a hurry and you can manually interrupt your program under the debugger …

How to profile C++ code running on Linux? Learn More
C/C++

How to convert int to string in C++?

Current C++ Starting with C++11, there’s a std::to_string function overloaded for integer types, so you can use code like: The standard defines these as being equivalent to doing the conversion with sprintf (using the …

How to convert int to string in C++? Learn More
C/C++

What is move semantics?

My first answer was an extremely simplified introduction to move semantics, and many details were left out on purpose to keep it simple. However, there is a lot more to …

What is move semantics? Learn More
C/C++

How to profile C++ code running on Linux?

If your goal is to use a profiler, use one of the suggested ones. However, if you’re in a hurry and you can manually interrupt your program under the debugger …

How to profile C++ code running on Linux? Learn More
C/C++

How to determine the size of an array in C?

In this post, you’ll learn how to find the number of elements the array can hold in C. How to determine the size of an array in C? You can …

How to determine the size of an array in C? Learn More
C/C++

How to iterate over the words of a string in C++?

In this post, we’ll learn how to iterate through a string word by word in C++. How to iterate through a string word by word in C++? Use this to …

How to iterate over the words of a string in C++? Learn More
C/C++ / Explanations

explicit keyword in C++

Short explanation: Suppose, you have a class String: Now, if you try: The character ‘x’ will be implicitly converted to int and then the String(int) constructor will be called. But, this is not what the user might …

explicit keyword in C++ Learn More
C/C++

What is the “–>” operator in C/C++? [Answered]

Query: Here’s the code: Output: I’d assume this is C, since it works in GCC as well. Where is this defined in the standard, and where has it come from? …

What is the “–>” operator in C/C++? [Answered] Learn More
C/C++

How to use extern to share variables between source files in C? [Answered]

Query explanation: I know that global variables in C sometimes have the extern keyword. What is an extern variable? What is the declaration like? What is its scope? This is related to sharing variables …

How to use extern to share variables between source files in C? [Answered] Learn More
C/C++ / Formatted Codes

How to remove trailing newline character from fgets() input? [Answered]

Sample problem: I am trying to get some data from the user and send it to another function in gcc. The code is something like this. However, I find that …

How to remove trailing newline character from fgets() input? [Answered] Learn More
C/C++

How to find the size of a pointer pointing to an array? [Answered]

Query explained: First off, here is some code: Is there a way to find out the size of the array that ptr is pointing to (instead of just giving its size, which …

How to find the size of a pointer pointing to an array? [Answered] Learn More
C/C++

What are the differences between a pointer variable and a reference variable in C++?

Query: I know references are syntactic sugar, so code is easier to read and write. But what is the difference between a pointer variable and a reference variable? What are …

What are the differences between a pointer variable and a reference variable in C++? Learn More
C/C++ / Java / Programming

Why is it faster to process a sorted array than processing an unsorted array? [Answered]

Query explained: Here is a piece of C++ code that shows some very peculiar behavior. For some strange reason, sorting the data (before the timed region) miraculously makes the loop almost …

Why is it faster to process a sorted array than processing an unsorted array? [Answered] Learn More
C/C++

How to resolve build errors due to circular dependency amongst classes? [Answered]

Sample problem: I often find myself in a situation where I am facing multiple compilation/linker errors in a C++ project due to some bad design decisions (made by someone else …

How to resolve build errors due to circular dependency amongst classes? [Answered] Learn More
C/C++

What is the copy-and-swap idiom? [Answered]

Query: What is the copy-and-swap idiom and when should it be used? Which problems does it solve? Does the idiom change when C++11 is used? The copy-and-swap idiom- Answer #1: …

What is the copy-and-swap idiom? [Answered] Learn More
C/C++ / Formatted Codes

How to iterate over the words of a string in C++? [Answered]

I’m trying to iterate over the words of a string. The string can be assumed to be composed of words separated by whitespace. Note that I’m not interested in C …

How to iterate over the words of a string in C++? [Answered] Learn More
C/C++ / Formatted Codes

scanf() leaves the new line char in the buffer | C [Answered]

Sample problem: I have the following program: As I read in the C book, the author says that scanf() left a new line character in the buffer, therefore, the program does not …

scanf() leaves the new line char in the buffer | C [Answered] Learn More

Posts navigation

1 2 Next

Featured Posts

From UNIX to Linux – History of Linux

21st November 202010th September 2022

Best themes for Ubuntu: Make Ubuntu Beautiful

20th October 202010th September 2022

Strings in Python

12th September 202010th September 2022

Is Python hard to learn? Top best learning resources

18th April 202010th September 2022

Recent posts

  • How to pad a string with zeroes to the left?
  • What is the difference between process and thread?
  • How to generate a random alpha-numeric string in Java?
  • How to auto-resize an image to fit a ‘div’ container?
  • How to get a Docker container’s IP address from the host?
  • How to display a JavaScript object?
Copyright © 2023 Programming Articles.
Powered by WordPress and HitMag.