Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
C Articles
Page 31 of 96
Explain Compile time and Run time initialization in C programming?
In C programming, array initialization can occur at two different times: compile time and run time. Understanding the difference between these two approaches is crucial for effective memory management and program design. Syntax // Compile time initialization type array_name[size] = {value1, value2, ..., valueN}; // Run time initialization type array_name[size]; // Values assigned during program execution Compile Time Initialization In compile time initialization, array values are specified directly in the source code when the array is declared. The compiler allocates memory and assigns values during the compilation process − #include ...
Read MoreWhy is the compiler not reading string after integer in C programming?
When reading string input after integer input in C, a common issue occurs where the string appears to be skipped. This happens because scanf() leaves a newline character in the input buffer after reading the integer. The Problem When you use scanf() to read an integer and then try to read a string using gets() or fgets(), the leftover newline character from the integer input is immediately consumed by the string function, causing it to terminate without reading actual string input. Solution Methods Method 1: Using a Temporary Character Read the leftover newline character using ...
Read MoreWhat is the common error occurred while using scanf() statement in C language?
The scanf() function in C is commonly used to read formatted input, but it often causes issues when reading strings after numeric values. The main problem occurs because scanf() leaves a newline character in the input buffer after reading numbers, which interferes with subsequent string input functions. Common Error When using scanf() to read numeric data followed by string input with gets() or fgets(), the string input is skipped because the leftover newline character from the previous scanf() is immediately consumed. Example: Demonstrating the Problem Here's a program that shows the common error when reading a ...
Read MoreHow to print a name multiple times without loop statement using C language?
In C programming, printing a name multiple times typically requires loops. However, we can achieve this without using any loop or goto statement by implementing recursive functions or using multiple printf statements. Syntax void recursiveFunction(parameters) { // Base case if (condition) return; // Process printf("text"); // Recursive call recursiveFunction(modified_parameters); } Method 1: Using ...
Read MoreFind the ASCII value of the uppercase character 'A' using implicit conversion in C language?
Implicit type conversion occurs when the compiler automatically converts a smaller data type to a larger data type without explicit casting. In C, when a char is used in an arithmetic operation, it gets implicitly converted to an int, allowing us to access its ASCII value. Syntax int ascii_value = character + 0; // Implicit conversion from char to int Example 1: ASCII Value of 'A' The following example demonstrates finding the ASCII value of uppercase character 'A' using implicit conversion − #include int main() { ...
Read MoreWhat are the 4 steps to convert C program to Machine code?
Converting a C program to machine code is a multi-stage process that transforms human-readable source code into executable machine instructions. This process involves four essential steps that work together to create a runnable program. The 4 Steps to Convert C Program to Machine Code The conversion process follows these four sequential steps − Writing and Editing − Creating the source code Preprocessing − Processing directives and preparing code Compiling − Translating to machine language Linking − Creating the final executable Source Code (.c) ...
Read MoreSignificance of Lambda Function in C/C++
Lambda Function − Lambda functions are anonymous inline functions that don't require any implementation outside the scope where they are defined. They provide a concise way to write small functions directly at the point of use. Lambda functions can also be stored in variables and treated as objects that can be called (called functors). When the compiler encounters a lambda function definition, it creates a custom object for that lambda. Note: Lambda functions are a C++11 feature and are NOT available in C. They are part of the C++ standard, not C. In C programming, you would use ...
Read MoreMaximum distinct lines passing through a single point in C
In computational geometry, finding the maximum number of distinct lines passing through a single point is a common problem. Given N lines defined by pairs of coordinates (x1, y1) and (x2, y2), we need to find how many lines with different slopes can pass through a single point. Syntax int maxDistinctLines(int n, int x1[], int y1[], int x2[], int y2[]); Approach We represent each line using the slope formula y = mx + c, where m is the slope calculated as − For non-vertical lines: slope = (y2 - y1) / (x2 ...
Read MoreMaximum given sized rectangles that can be cut out of a sheet of paper in C
We are given the dimensions of a sheet of paper, its Length L and Breadth B. Also, we are given the dimensions of a smaller rectangle, its length l and breadth b. The goal is to find the maximum number of smaller rectangles that can be cut out of the sheet of paper. We will follow these steps − First, try horizontal alignment: divide the sheet length L by rectangle length l, and sheet breadth B by rectangle breadth b, then multiply to get the count. Then try vertical alignment (rotate the rectangle 90°): divide sheet length ...
Read MoreMaximum number of candies that can be bought in C
We are given an array of candies[] of length stored in 'size'. Each element candies[i] has a number for candies of type i. The goal is to buy as many candies as possible for any amount of money. The conditions are as given − If you purchase X[i] of type i (0
Read More