echo '' ;

Category Archives: Programming Language

C Programming Language

C Quiz-6

Participating in a C quiz can offer several benefits for individuals looking to improve their programming skills and knowledge of the C programming language. Here are some potential advantages:

  • Resume Enhancement: Mentioning participation and achievements in C quizzes on a resume or portfolio can showcase a candidate’s dedication to learning and improving their programming skills, potentially making them more attractive to employers.
Read more… →

C Quiz-5

Participating in a C quiz can offer several benefits for individuals looking to improve their programming skills and knowledge of the C programming language. Here are some potential advantages:

  • Continuous Learning: Regular participation in C quizzes encourages continuous learning. As programming languages evolve, staying engaged with quizzes helps individuals stay current with the latest updates and best practices in C programming.
Read more… →

C Quiz-4

Participating in a C quiz can offer several benefits for individuals looking to improve their programming skills and knowledge of the C programming language. Here are some potential advantages:

  1. Preparation for Interviews: C programming quizzes often include questions similar to those asked in technical interviews for software development positions. Participating in quizzes can help individuals prepare for such interviews and increase their confidence in discussing C-related topics.
  2. Community Engagement: Online platforms that host C quizzes often have forums or communities where participants can discuss questions, share insights, and learn from each other. Engaging with a community can broaden one’s perspective and provide additional learning resources.
Read more… →
C Programming Language

C Quiz-3

Participating in a C quiz can offer several benefits for individuals looking to improve their programming skills and knowledge of the C programming language. Here are some potential advantages:

  1. Competition and Motivation: Quizzes with a competitive element can motivate participants to strive for better performance. Healthy competition can encourage individuals to push themselves and learn more to achieve higher scores.
  2. Feedback and Learning Opportunities: After completing a quiz, participants typically receive feedback on their performance. This feedback can include explanations for correct and incorrect answers, providing valuable learning opportunities.
Read more… →
C Programming Language

C Quiz-2

Participating in a C quiz can offer several benefits for individuals looking to improve their programming skills and knowledge of the C programming language. Here are some potential advantages:

  1. Problem-Solving Practice: Many C quizzes include practical problem-solving questions that require participants to apply their programming knowledge to solve specific problems. This helps improve problem-solving skills and the ability to implement algorithms in C.
  2. Time Management: C Quizzes often have a time limit for each question, helping participants develop effective time management skills. This is particularly valuable in a real-world programming environment where efficient coding is essential.
Read more… →

C Example – Little Endian and Big Endian


Little and Big Endian are two different byte orderings used to represent multibyte data types, such as integers, in computer memory.

Pre-Request to read this first: What is Little and Big Endian in System

The choice between Both is crucial when data is transferred between systems with different byte orderings. Network protocols and file formats often specify the byte order to ensure compatibility between systems. Many modern architectures, especially those based on x86 and x86-64, use Little-Endian by default.

Read more… →

C Example – Swapping

C Example -In programming, swapping values is a fundamental operation that can find use in various applications across different domains.

Specific use cases-1 of C Example – Swapping

Database Management:

  • Reordering Data: You can use swapping rows in a database table to change the order of records based on certain criteria, such as alphabetical order or chronological order.
  • Optimization: Swapping rows can sometimes be part of database optimization strategies, like minimizing disk I/O by reorganizing data to reduce fragmentation.

Matrix Operations:

  • Matrix Transposition: Swapping rows with columns is fundamental in transposing a matrix, where the rows become columns and vice versa.
  • Row Reduction: Techniques like Gaussian elimination in linear algebra require swapping rows to solve systems of linear equations or find matrix inverses.

Sorting Algorithms:

  • Heap Sort: During the beatification process, swapping rows might be necessary. This process involves reordering elements to satisfy the heap property.
  • Radix Sort: For multidimensional data, swapping entire rows or columns may be part of the sorting process.

Data Analysis and Manipulation:

  • Reorganizing Data: Swapping rows or columns can help in rearranging data for better analysis, such as grouping similar data together or aligning data for comparison.
  • Data Cleaning: In data preprocessing tasks, swapping rows or columns might be necessary to remove duplicates or standardize data formats.

Specific use cases-2 of C Example – Swapping

Graphics and Visualization:

  • Image Processing: Swapping rows or columns of pixel data is common in image processing tasks like rotation, flipping, or resizing images.
  • Data Visualization: In tools like spreadsheets or data visualization software, users may swap rows or columns to customize the presentation of data for better interpretation.

Parallel Processing:

  • Data Partitioning: When distributing data across multiple processing units in parallel computing, swapping rows or columns can be used to redistribute data chunks for load balancing or efficient computation.
  • Data Merging: After parallel processing tasks, swapping rows or columns may be necessary to merge results from different processing units into a single coherent dataset.

Encryption and Compression:

  • Data Obfuscation: Swapping rows or columns can be part of encryption or compression algorithms to scramble data for security or reduce redundancy for compression.

C Program to Swap Two Numbers

Swapping Two Numbers (Folder)


C Program to Swapping Strings (Folder)

C Examples – Addition

In this “C Examples Addition” example, we’ll explore a simple C program that demonstrates addition. Addition is one of the fundamental arithmetic operations, and understanding how to perform it in C can be useful for building more complex programs.
Our program will prompt the user to enter two integers, then it will add them together and display the result. We’ll achieve this using basic input/output functions (printf() and scanf()) for user interaction and a simple loop to perform the addition.
Let’s dive into the code and understand how it works!

Read more… →

C Examples – Time Delay

Time delay is necessary for some cases in programming. for example, if you wanna print some string with some delay or wanna write some value in file frequently with some delay or need to check the excel file value with some delay like many use cases. To make a delay in application execution, we have two options like can write own custom user to define a function as well as can use some pre-defined library functions in C. In many ways, users can write the time delay functions like using for loop, while loop, do-while loop as well as a separate function in all. Here will discuss about C Examples Time Delay.

Read more… →

C Example – Hello World

Here below are many C Example Hello World codes that are available related to Hello World if you have any doubts please post in the comment section. The “Hello World” example in the C programming language is often the first program beginners encounter when learning to code. It’s a simple program that prints “Hello, World!” to the screen. This program serves as a basic introduction to programming syntax and structure in C.

Example: Hello World

This “Hello world” C Example is one of the good in anything startup. Here we are going to print the "ArunEworld" string in the console.

For the below code, you should know the following

Read more… →

C Library – conio.h

The conio.h header file is a C library that provides functions for console input and output in the DOS and Windows environments. “Conio” stands for “console input/output”. This header file is not part of the standard C library and is specific to DOS and Windows systems.

Some commonly used functions declared in conio.h include:

  1. clrscr(): Clears the screen.
  2. getch(): Reads a character directly from the console without echoing it.
  3. getche(): Reads a character directly from the console and echoes it.
  4. cprintf(): Prints formatted output to the console.
  5. cscanf(): Reads formatted input from the console.

It’s important to note that conio.h is not standard and is not portable across different platforms or compilers. It was widely used in older DOS-based C programming, but it’s generally not recommended for modern development due to its lack of portability and non-standard nature. Most modern compilers, especially those targeting Unix-like systems, do not support conio.h. Instead, developers typically use standard input/output functions from stdio.h for console I/O.

getch()

The getch() function in conio.h reads a single character from keyboard. It doesn’t uses any buffer, so entered data is not displayed on the output screen.

Read more… →

C Library – windows.h

The windows.h header file is a fundamental header file for the Microsoft Windows operating system. It includes declarations for a wide range of functions and data types used in Windows programming. Here’s a basic example demonstrating the usage of windows.h for creating a simple Windows GUI application:

C Library – windows.h File

#include <windows.h>

// Function prototype for the window procedure
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

int main() {
    // Get the handle to the instance of this application
    HINSTANCE hInstance = GetModuleHandle(NULL);

    // Create the main window
    HWND hwnd = CreateWindowEx(
        0,                              // Optional window styles
        L"WindowClass",                 // Window class
        L"My First Window",             // Window title
        WS_OVERLAPPEDWINDOW,            // Window style

        // Size and position
        CW_USEDEFAULT, CW_USEDEFAULT, 800, 600,

        NULL,       // Parent window    
        NULL,       // Menu
        hInstance,  // Instance handle
        NULL        // Additional application data
    );

    // Display the window
    ShowWindow(hwnd, SW_SHOWNORMAL);

    // Enter the message loop
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return 0;
}

// The window procedure
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    switch (uMsg) {
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
        default:
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
    return 0;
}

This above example creates a simple window using the Windows API. The WindowProc function is the window procedure, which handles messages for the main window. The CreateWindowEx function creates the main window, and the ShowWindow function displays it. The program then enters a message loop (while (GetMessage...)) where it waits for and processes messages until the user closes the window.

Remember that this is just a basic example, and real-world Windows applications will involve more complexities and considerations. Additionally, GUI programming in Windows often involves using additional libraries, such as MFC (Microsoft Foundation Classes) or newer frameworks like WinUI.

Predefined functions of C Library – windows.h

The windows.h header in Windows programming provides declarations for various functions, data types, and constants used in Windows API. Here are some commonly used predefined functions available in windows.h:

C Library – windows.h predefined functions List

C Library – windows.h predefined functions

Note

These are just a few examples, and there are many more functions provided by Windows.h for various purposes. When working with Windows programming, documentation is an essential resource to understand and use these functions effectively. The next section only discussed Sleep() function.

sleep() in C Library – windows.h

if you have the following questions like

  • How to use the delay function in C?
  • How to use the C program delay function in Windows?

Here is your solution,

If you wanna use the delay feature, you can use the Sleep() function in the Windows platform, based on the compiler the Sleep() will call in different library files(Some times Sleep function will be winbase.h, Sometimes different). Don’t worry about that, if you include the windows.h the header file, that will be taken care of. why because everything all the sleep function necessary headers are already included in windows.h the file.

  • Rule-1: You should add the header file #include <windows.h>
  • Rule-2: Sleep() function first letter always Uppercase, if you declare in the small case the compiler might generate error “Undefined reference to sleep”.
  • Rule-3: Sleep() function argument (Milliseconds) should be unsigned long type. If your call [Example : Sleep("ArunEworld")] Sleep() function with char type or other types, the compiler will generate an Error.

Please note that the sleep function may not be very precise, and the actual delay could be slightly longer due to system-related factors. If you need more precise timing, you might want to explore other methods or libraries for that purpose.

Sleep() Example-1

Code

#include <stdio.h>
#include <unistd.h>  // for sleep function

int main() {
    printf("ArunEworld: This is before the delay.\n");

    // Sleep for 3 seconds
    sleep(3);

    printf("ArunEworld: This is after the delay.\n");

    return 0;
}

Explanation

In this above example, the program will print the first message, then pause for 3 seconds using sleep(3), and finally print the second message after the delay.

Remember to include the <unistd.h> header for the sleep function to work.

Sleep() Example-2

The below code will be printed ArunEworld website every 1 second

#include <stdio.h>
#include <Windows.h>
int main() 
{
	while(1)
	{
		//print the aruneworld website address
		printf("www.ArunEworld.com.\r\n");
		
		//make a delay every in millisecond
		Sleep(1000);
	}
	
	return 0; 
}

Slep() Example-3

#include <stdio.h>
#include <Windows.h>
int main() 
{
	while(1)
	{
		//print the aruneworld website address
		printf("www.ArunEworld.com.\r\n");
		
		//make a delay every in millisecond
		Sleep("ArunEworld");
	}
	
	return 0; 
}

The above code will show the Error like "[Note] expected 'DWORD' but argument is of type 'char *'". Why because Sleep() the argument should be unsigned long. here ‘ArunEworld' is a charter pointer.

Refer to the C Examples – Time Delay


Next

C – Basic
C – Operator
C – Decision making, Branching, Looping
C – Functions
C – Storage Class
C – Extern
C – Array
C – Pointer
C – Memory Allocation
C – Structure
C – Union
C – Structure and Union
C – Macros
C – Preprocessor and Macros
C – File Management
C – Coding Standard
C – Compilers
C – Compiling Process
C File Management
C Library
C Example

C Library – stdlib.h

stdlib.h in standard C Library header file that provides various functions to perform general utility tasks. It includes functions for memory allocation, process control, random number generation, string conversion, and other fundamental operations.

Key functions include malloc() for dynamic memory allocation, free() to release allocated memory, exit() for program termination, atoi() for converting strings to integers, and rand() for generating pseudo-random numbers.

Read more: C Library – stdlib.h

Additionally, <stdlib.h> declares the NULL macro for null pointers and defines the EXIT_SUCCESS and EXIT_FAILURE constants for program termination status.

Overall, <stdlib.h> is essential for many C programs, offering foundational functionalities crucial for memory management, program flow control, and data conversion.

Functions List

functions are in below table, Refer this link for more info

FunctionDescription
abort()Stop a Program.
abs()Calculate Integer Absolute Value.
atexit()Record Program Ending Function.
atof()Convert Character String to Float
atoi()Convert Character String to Integer
atol() & atoll()Convert Character String to Long or Long Long Integer
bsearch()Search Array
calloc()Reserve and Initialize Storage
_C_Quickpool_Debug()Modify Quick Pool Memory Manager Characteristics
_C_Quickpool_Init()Initialize Quick Pool Memory Manager.
_C_Quickpool_Report()Generate Quick Pool Memory Manager Report
div()Calculate Quotient and Reminder
exit()End Program
free()Release Storage Blocks
_gcvt1()Convert Floating Point to String
getenv()Search for Enviroment Variable
_itoa1()Convert Integer to String
_ltoa1()Convert Integer to String
labs()Calculate absolute value of long and long long Integer
llabs()Calculate absolute value of long and long long Integer
ldiv()Perform Long and Long Long Division
lldiv()Perform Long and Long Long Division
malloc()Reserve Storage Block
mblen()Determine Length of Multibyte Character
mbstowcs()Convert Multibyte String to a Wide Character String
mbtowc()Convert Multibyte Character to a Wide Character
putenv()Change/Add Environmental Variable
qsort()Sort Array
rand()Generate Random Number
rand_r()Generate Random Number
realloc()Change Reserved Storage Block Size
srand()Set Seed fr rand() Function
strtod()Convert Character String to Double, Float, and Long Double
strtod32()Convert Character String to Decimal Floating-Point
strtod64()Convert Character String to Decimal Floating-Point
strtod128()Convert Character String to Decimal Floating-Point
strtof()Convert Character String to Double, Float, and Long Double
strtol()Convert Character String to Long and Long Long Integer
strtold()Convert Character String to Double, Float, and Long Double
strtoll()Convert Character String to Long and Long Long Integer
strtoul()String to unsigned Long Integer
strtoull()String to Unsigned Long Long Integer
system()Execute a command
_ultoa1()Convert Unsigned Long Integer to String.
wcstombs()Convert a Wide Character to a Multibyte Character String
wctomb()Convert a Wide Character to a Multibyte Character
Read more… →

C Library – stdio.h

The stdio.h header file in C is a standard input-output library that provides functions for input and output operations. It stands for “standard input-output header”. This header file declares several functions, including printf, scanf, fopen, fclose, fread, fwrite, etc., as well as various macros and data types.

  • std means Standard and io means Input-output statements
  • These statements are used to get and put data on computers
  • Ex-1: Can put data to a computer via the keyboard.
  • Ex-2: Can get data and see that in Monitor.
  • Input-output statements are used as a function in c language
  • stdio.h file contains that statements statements
  • So if we use these functions should include stdio.h , functions are  scanf()  , printf()   , getchar() , gets() , putchar() ,  puts().

Here’s a brief overview of some commonly used functions and macros declared in stdio.h:

  1. printf: Used to print formatted output to the standard output (usually the console).
  2. scanf: Used to read formatted input from the standard input (usually the keyboard).
  3. fprintf, fscanf, sprintf, sscanf: Variants of printf and scanf for performing formatted I/O operations on files or strings.
  4. FILE: Data type representing a file stream used by functions like fopen, fclose, fread, fwrite, etc.
  5. stdin, stdout, stderr: Predefined file streams representing standard input, standard output, and standard error respectively.

Including stdio.h at the beginning of your C program allows you to use these functions and macros. It’s an essential header file for most C programs, as it provides basic input and output capabilities.

Read more… →

C – structures and unions

In C programming, structures (struct) and unions (union) are fundamental data types used to organize and manipulate related data. They both allow grouping multiple variables of different data types into a single entity. However, they have distinct characteristics and usage scenarios.

A structure (struct) is a composite data type that enables bundling together variables of different types under a single name. Structures commonly use to represent records, objects, or complex data structures, and each variable within a structure is called a member, which can be of any data type, including other structures or arrays.

On the other hand, a union (union) is similar to a structure but with a key difference: all members of a union share the same memory location. This means that a union variable can hold only one value at a time, regardless of the number of members it has. Programmers often use unions when memory efficiency is crucial or when different data types need to share the same memory space.

In this introduction to “C – struct and union,” we will explore the syntax, usage, and differences between structures and unions in C, along with common scenarios where each data type is appropriate. We will also discuss best practices and potential pitfalls associated with using structures and unions in C programming.

differences between a union and a structure:

FeatureUnionStructure
DefinitionA union is a data type that allows storing different types of data in the same memory location.A structure is a composite data type that allows storing different types of data in a single variable.
Memory UsageOccupies memory space equal to the size of the largest member.Occupies memory space equal to the sum of the sizes of its members.
Data SharingShares memory among its members.Each member has its own memory space.
Accessing MembersAll members share the same memory location, so only one member can be accessed at a time.Each member has its own memory location, and all members can be accessed independently.
Use CasesUseful when different data types need to share the same memory location to conserve memory.Suitable for grouping related data together, such as representing a record or object.
  • The difference between structure and union is, … The amount of memory required to store a structure variable is the sum of the size of all the members.
  • On the other hand, in case of unions, the amount of memory required is always equal to that required by its largest member.

Example -1 : struct inside union.

Consider the following C declaration, Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, is (GATE CS 2000)

struct { 
    short s[5];
    union { 
         float y; 
         long z; 
    }u; 
}

Answer : 18

Short array s[5] will take 10 bytes as size of short is 2 bytes. When we declare a union, memory allocated for the union is equal to memory needed for the largest member of it, and all members share this same memory space. Since u is a union, memory allocated to u will be max of float y(4 bytes) and long z(8 bytes). So, total size will be 18 bytes (10 + 8).


NEXT

C – Basic
C – Operator
C – Decision making, Branching, Looping
C – Functions
C – Storage Class
C – Extern
C – Array
C – Pointer
C – Memory Allocation
C – Structure
C – Union
C – Structure and Union
C – Macros
C – Preprocessor and Macros
C – File Management
C – Coding Standard
C – Compilers
C – Compiling Process
C File Management
C Library
C Example