Found 1339 Articles for C

Program to convert given number of days in terms of Years, Weeks and Days in C

Sunidhi Bansal
Updated on 18-Oct-2019 07:51:37

4K+ Views

You are given with number of days, and the task is to convert the given number of days in terms of years, weeks and days.Let us assume the number of days in a year =365Number of year = (number of days) / 365Explanation-: number of years will be the quotient obtained by dividing the given number of days with 365Number of weeks = (number of days % 365) / 7Explanation-: number of weeks will be obtained by collecting the remainder from dividing the number of days with 365 and further dividing the result with number of days in a week ... Read More

POSIX Thread Libraries

Arnab Chakraborty
Updated on 17-Oct-2019 08:49:29

1K+ Views

Pthreads refers to the POSIX standard (IEEE 1003.1c) defining an API for thread creation and synchronization. This defines specification for thread behavior, not an implementation. The specification can be implemented by OS designers in any way they wish. So many systems implement the Pthreads specification; most are UNIX-type systems, including Linux, Mac OS X, and Solaris. Although Windows doesn’t support Pthreads natively, some third-party implementations for Windows are available. The C program shown in Figure 4.9 demonstrates the basic Pthreads API for constructing a multithreaded program that calculates the summation of a nonnegative integer in a separate thread. Separate threads ... Read More

Implicit Threading and Language-based threads

Arnab Chakraborty
Updated on 17-Oct-2019 08:46:49

4K+ Views

Implicit ThreadingOne way to address the difficulties and better support the design of multithreaded applications is to transfer the creation and management of threading from application developers to compilers and run-time libraries. This, termed implicit threading, is a popular trend today.Implicit threading is mainly the use of libraries or other language support to hide the management of threads. The most common implicit threading library is OpenMP, in context of C.OpenMP is a set of compiler directives as well as an API for programs written in C, C++, or FORTRAN that provides support for parallel programming in shared-memory environments. OpenMP identifies ... Read More

Windows thread API in the C program

Arnab Chakraborty
Updated on 16-Oct-2019 10:39:12

3K+ Views

Threads are created in the Windows API using the CreateThread() function, and—just as in Pthreads—a set of attributes like security information, the size of the stack, and a flag for the thread is passed to this function. In the below program, we use the default values for these attributes. (The default values do not initially set the thread to a suspended state and instead make it eligible to be run by the CPU scheduler.) Once the summation thread is created, the parent must wait for it to complete before outputting the value of Sum, as the value is set by ... Read More

Arc function in C

sudhir sharma
Updated on 16-Oct-2019 07:12:56

3K+ Views

In the C programming language, there is an option to create an arc of a circle of a given radius with a given center coordinates and degree of the arc.The arc() function is used to create an arc. This arc function is included in graphics.h library in C which contains methods that can draw figures on the output screen.Syntaxvoid arc(int x, int y, int startangle, int endangle, int radius);Now, let's get deep into the function and understand each parameter passed and output returned by the function.Parametersx − type = int, function: defines the x coordinate of the center of the arc.y ... Read More

Advanced master theorem for divide and conquer recurrences

sudhir sharma
Updated on 08-Jun-2020 05:44:13

2K+ Views

Divide and conquer is an algorithm that works on the paradigm based on recursively branching problem into multiple sub-problems of similar type that can be solved easily.ExampleLet’s take an example to learn more about the divide and conquer technique −function recursive(input x size n)    if(n < k)       Divide the input into m subproblems of size n/p.       and call f recursively of each sub problem    else       Solve x and returnCombine the results of all subproblems and return the solution to the original problem.Explanation − In the above problem, the problem ... Read More

Grand Central Dispatch (GCD)

Arnab Chakraborty
Updated on 11-Oct-2019 12:48:37

901 Views

Grand Central Dispatch (GCD) - a technology for Apple’s Mac OS X and iOS operating systems-is a combination of extensions to the C language, an API, and a run-time library that allows application developers to identify sections of code to run in parallel. Like OpenMP, GCD manages most of the details of threading. GCD identifies extensions to the C and C++ languages known as blocks. A block is simply a self-contained unit of work. It is specified by a caret ˆ inserted in front of a pair of braces { }. A simple example of a block is shown below ... Read More

What is OpenMP?

Arnab Chakraborty
Updated on 11-Oct-2019 12:45:48

8K+ Views

OpenMP is a set of compiler directives as well as an API for programs written in C, C++, or FORTRAN that provides support for parallel programming in shared-memory environments. OpenMP identifies parallel regions as blocks of code that may run in parallel. Application developers insert compiler directives into their code at parallel regions, and these directives instruct the OpenMP run-time library to execute the region in parallel. The following C program illustrates a compiler directive above the parallel region containing the printf() statement −#include #include int main(int argc, char *argv[]){    /* sequential code */    #pragma omp ... Read More

Windows Anonymous Pipe

Arnab Chakraborty
Updated on 11-Oct-2019 12:18:27

1K+ Views

Windows anonymous pipes are actually Ordinary pipes, and they behave similarly to their UNIX counterparts: they are unidirectional and employ parent-child relationships between the communicating processes. In addition, reading and writing to the pipe can be accomplished with the ordinary ReadFile() and WriteFile() functions. The Windows API use CreatePipe() function for creating pipes, which is passed four parameters. The parameters provide separate handles forreading andwriting to the pipeAn instance of the STARTUPINFO structure, used to specify that the child process is to inherit the handles of the pipe.the size (in Bytes) of the pipe may be specified.Windows requires the programmer ... Read More

C/C++ Pointer Puzzle?

sudhir sharma
Updated on 07-Oct-2019 08:19:16

434 Views

A Pointer is a variable that stores the address of another variable. The data type of the pointer is the same as the data type as the variable.In this puzzle you need to know the size of the pointer that is being used. The puzzle checks our understanding of pointers by asking you the size of variable.The size of int is 4 bytes, whereas the size of int pointer is 8. Now, let’s test your skills with the following exercise in c++ programming language.Example Live Demo#include using namespace std; int main() {    int a = 6 ;    int ... Read More

Advertisements