• Register

Recent posts tagged c

7 0 3 min.
Error is an illegal operation performed by the user which results in abnormal working of the program.Programming errors often remain undetected until the program is compiled or executed. Some of the errors inhibit the program from getting compiled or...
posted 13 hours ago Yogesh Sharma 247 points
1 0 4 min.
This function cancel a particular thread using thread id. This function send a cancellation request to the thread.Syntax : – int pthread_cancel(pthread_t thread);// C program to demonstrates cancellation of self thread // using thread id#i...
posted 13 hours ago Yogesh Sharma 247 points
1 0 4 min.
“Setjump” and “Longjump” are defined in setjmp.h, a header file in C standard library.setjump(jmp_buf buf) : uses buf to remember current position and returns 0.longjump(jmp_buf buf, i) : Go back to place buf is poin...
posted 14 hours ago Yogesh Sharma 247 points
4 0 1 min.
Just declare the printf() function taken from “stdio.h” header file.//Declare the printf() functionint printf(const char *format, ...); int main(){  printf( "Hello World" );  return 0;}Output: Hello Worl...
posted 14 hours ago Yogesh Sharma 247 points
4 0 2 min.
memmove() is similar to memcpy() as it also copies data from a source to destination. memcpy() leads to problems when source and destination addresses overlap as memcpy() simply copies data one by one from one location to another. For example conside...
posted 14 hours ago Yogesh Sharma 247 points
4 0 6 min.
The memcpy() function is used to copy a block of data from a source address to a destination address.Its prototype.void * memcpy(void * destination, const void * source, size_t num);The idea is to simply typecast given addresses to char *(char takes ...
posted 14 hours ago Yogesh Sharma 247 points
4 0 5 min.
Using a macro that defines main#include<stdio.h>#define fun mainint fun(void){    printf("Hii");    return 0;}Output: HiiUsing Token-Pasting OperatorThe above solution has word ‘main&rsquo...
posted 14 hours ago Yogesh Sharma 247 points
4 0 6 min.
#include <math.h>#include <stdio.h>int intToStr(int x, char str[], int d){    int i = 0;    while (x) {        str[i++] = (x % 10) + '0';  &...
posted 14 hours ago Yogesh Sharma 247 points
4 0 4 min.
 #include <stdio.h>#include <time.h>// A function that terminates when enter key is pressedvoid fun(){    printf("fun() starts \n");    printf("Press enter to stop fun \n");...
posted 14 hours ago Yogesh Sharma 247 points
4 0 3 min.
/* A C program that does not terminate when Ctrl+C is pressed */#include <stdio.h>#include <signal.h>  void sigintHandler(int sig_num){    signal(SIGINT, sigintHandler);    printf("\n...
posted 14 hours ago Yogesh Sharma 247 points
1 0 1 min.
Recursive// A recursive C program to print all numbers from 1// to N without semicolon#include<stdio.h>#define N 10int main(int num){    if (num <= N && printf("%d ", num) && main(num + 1)) ...
posted 14 hours ago Yogesh Sharma 247 points
1 0 7 min.
lseek is a system call that is used to change the location of the read/write pointer of a file descriptor. The location can be set either in absolute or relative terms.Function Definition:off_t lseek(int fildes, off_t offset, int whence);For example,...
posted 14 hours ago Yogesh Sharma 247 points
1 0 3 min.
ftell() in C is used to find out the position of file pointer in the file with respect to starting of the file.Syntax of ftell() is:long ftell(FILE *pointer) Consider below C program. The file taken in the example contains the following data :“...
posted 15 hours ago Yogesh Sharma 247 points
1 0 2 min.
The C library function void rewind(FILE *stream) sets the file position to the beginning of the file of the given stream.DeclarationFollowing is the declaration for rewind() function.void rewind(FILE *stream)Parametersstream &minu...
posted 15 hours ago Yogesh Sharma 247 points
1 0 4 min.
 fseek() is used to move file pointer associated with a given file to a specific position.Syntax:int fseek(FILE *pointer, long int offset, int position) pointer: pointer to a FILE object that identifies the stream. offset: number of bytes to off...
posted 15 hours ago Yogesh Sharma 247 points
1 0 3 min.
Memory leak occurs when programmers create a memory in heap and forget to delete it.Memory leaks are particularly serious issues for programs like daemons and servers which by definition never terminate./* Function with memory leak */#include <std...
posted 15 hours ago Yogesh Sharma 247 points
3 1 4 min.
 Size of dynamically allocated memory can be changed by using realloc().Syntax :void *realloc(void *ptr, size_t size);realloc deallocates the old object pointed to by ptr and returns a pointer to a new object that has the size specified by size....
posted 17 hours ago Yogesh Sharma 247 points
3 0 6 min.
The name malloc and calloc() are library functions that allocate memory dynamically. It means that memory is allocated during runtime from the heap segment.Initialization: calloc() allocates the memory and also initializes th...
posted 17 hours ago Yogesh Sharma 247 points
3 0 5 min.
A typical memory representation of a C program consists of the following sections.1. Text segment 2. Initialized data segment 3. Uninitialized data segment 4. Stack 5. Heap A typical memory layout of a running process :1. Tex...
posted 17 hours ago Yogesh Sharma 247 points
3 0 3 min.
Function in C language with exampleIn this article, we learn functions in C language programming. A function is a block of statements and performs a specific every call. If you write C code and use a single same task to perform multiple times then us...
posted 17 hours ago usmanhashmi 121 points