Found 1401 Articles for C

Database Connectivity using C/C++

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

3K+ Views

In this section, you will learn how to use SQLite in C/C++ programs.InstallationBefore you start using SQLite in our C/C++ programs, you need to make sure that you have SQLite library set up on the machine. You can check the SQLite Installation chapter to understand the installation process.C/C++ Interface APIsFollowing are important C/C++ SQLite interface routines, which can suffice your requirement to work with SQLite database from your C/C++ program. If you are looking for a more sophisticated application, then you can look into SQLite official documentation.Serial NoAPI & Description1sqlite3_open(const char *filename, sqlite3 **ppDb)This routine opens a connection to an ... Read More

lvalue and rvalue in C

Nitya Raut
Updated on 30-Jul-2019 22:30:25

8K+ Views

An lvalue (locator value) represents an object that occupies some identifiable location in memory (i.e. has an address).rvalues are defined by exclusion. Every expression is either an lvalue or an rvalue, so, an rvalue is an expression that does not represent an object occupying some identifiable location in memory.For example, An assignment expects an lvalue as its left operand, so the following is valid:int i = 10; But this is not: int i; 10 = i;This is because i has an address in memory and is a lvalue. While 10 doesn't have an identifiable memory location and hence is an ... Read More

fork() in C

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

3K+ Views

In this section we will see what is the fork system call in C. This fork system call is used to create a new process. This newly created process is known as child process. The current process which is creating another child process is called the parent process.A child process uses the same program counter, CPU register, same files that are used by the parent process.The fork() does not take any parameter, it returns integer values. It may return three types of integer values.Negative Number: It returns negative number when child process creation is failedZero Value: It returns Zero for ... Read More

Assertions in C/C++

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

322 Views

Here we will see what is assertions in C/C++. The C library macro void assert(int expression) allows diagnostic information to be written to the standard error file. In other words, it can be used to add diagnostics in your C program.Following is the declaration for assert() Macro.void assert(int expression);The parameter of this assert() is expression − This can be a variable or any C expression. If expression evaluates to TRUE, assert() does nothing. If expression evaluates to FALSE, assert() displays an error message on stderr (standard error stream to display error messages and diagnostics) and aborts program execution.Example Code#include ... Read More

Multithreading in C

Nitya Raut
Updated on 30-Jul-2019 22:30:25

20K+ Views

Multithreading is a specialized form of multitasking and a multitasking is the feature that allows your computer to run two or more programs concurrently. In general, there are two types of multitasking: process-based and thread-based.Process-based multitasking handles the concurrent execution of programs. Thread-based multitasking deals with the concurrent execution of pieces of the same program.A multithreaded program contains two or more parts that can run concurrently. Each part of such a program is called a thread, and each thread defines a separate path of execution.C does not contain any built-in support for multithreaded applications. Instead, it relies entirely upon the ... Read More

Print “Hello World” without using any header file in C

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

920 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, Example Codeint printf(const char *text, ...); int main() {    printf( "Hello World" );    return 0; }OutputHello Worldn 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 ... Read More

Execute both if and else statements simultaneously in C/C++

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

140 Views

In this section we will see how to execute the if and else section simultaneously in a C or C++ code. This solution is little bit tricky.When the if and else are executed one after another then it is like executing statements where if-else are not present. But here we will see if they are present how to execute them one after another.Example Code#include using namespace std; int main() {    int x = 10;    if(x > 5)   {       lebel_1: cout

Implement your own itoa() in C

Nitya Raut
Updated on 30-Jul-2019 22:30:25

1K+ Views

In this section we will see how to convert an integer number to a string.The logic is very simple. Here we will use the sprintf() function. This function is used to print some value or line into a string, but not in the console. This is the only difference between printf() and sprintf(). Here the first argument is the string buffer. where we want to save our data.Input: User will put some numeric value say 42Output: This program will return the string equivalent result of that number like “42”Algorithm:Step 1: Take a number as argument Step 2: Create an empty ... Read More

Bit Fields in C

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

208 Views

In this section we will what is bit fields in C.Suppose your C program contains a number of TRUE/FALSE variables grouped in a structure called status, as follows –struct {    unsigned int widthValidated;    unsigned int heightValidated; } status;This structure requires 8 bits of memory space but in actual, we are going to store either 0 or 1 in each of the variables. The C programming language offers a better way to utilize the memory space in such situations.If you are using such variables inside a structure then you can define the width of a variable which tells the ... Read More

Switch case statement in C

Nitya Raut
Updated on 30-Jul-2019 22:30:25

1K+ Views

A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch case.The syntax for a switch statement in C programming language is as follows −switch(expression) {    case constant-expression :       statement(s);       break; /* optional */    case constant-expression :       statement(s);       break; /* optional */       /* you can have any number of case statements */    default : /* Optional */       ... Read More

Advertisements