Tutorialspoint

Compile and Execute C++0x Onlinej

c

#include<stdio.h>

main(){
	printf("%d", sizeof('a'));
}

Compile and Execute C++0x Onlinej

c

#include<stdio.h> 
  
int main() { 
    int a, b, line = 12; 
  
    for (a = line/2; a <= line; a = a+2) { //for the upper part of the heart
        for (b = 1; b < line-a; b = b+2) //create space before the first peak         
            printf(" "); 
   
        for (b = 1; b <= a; b++) //print the first peak
            printf("*"); 
   
        for (b = 1; b <= line-a; b++) //create space before the first peak
            printf(" "); 
           
        for (b = 1; b <= a-1; b++) //print the second peak
            printf("*"); 
        printf("\n"); 
    } 

    for (a = line; a >= 0; a--) { //the base of the heart is inverted triangle
        for (b = a; b < line; b++) //generate space before triangle
            printf(" "); 
  
        for (b = 1; b <= ((a * 2) - 1); b++) //print the triangle
            printf("*"); 
  
        printf("\n");   
    } 
}

Compile and Execute C++0x Onlinej

c

#include<stdlib.h>
int main() {
	int a = 7;
	float b = 7.6;
	void *p;
	p = &a;
	printf("Integer variable is = %d", *( (int*) p) );
	p = &b;
	printf("\nFloat variable is = %f", *( (float*) p) );
	return 0;
}

Compile and Execute C++0x Onlinej

c

#include <stdio.h>
int main() {
	int *p= NULL;//initialize the pointer as null.
	printf("The value of pointer is %u",p);
	return 0;
}

Compile and Execute C++0x Onlinej

c

#include<stdio.h>

main(){
	printf("%d", sizeof('a'));
}

Compile and Execute C++0x Onlinej

c

#include <stdio.h>
void show(int x) { 
	printf("Value of x is %d\n", x); 
}
int main() { 
	void (*x)(int); x = &show;
	(*x)(7);
	return 0; 
}

Compile and Execute C++0x Onlinej

c

#include <stdio.h>
#include <stdlib.h>
int main() {
	char file1[100];
	char file2[100];
	char file3[100];
	printf("Enter first file name: ");
	scanf("%s", file1);
	printf("Enter second file name: ");
	scanf("%s", file2);
	printf("Enter third file name: ");
	scanf("%s", file3);
	FILE *fp1 = fopen(file1, "r");
	FILE *fp2 = fopen(file2, "r");
	FILE *fp3 = fopen(file3, "w");
	char c;
	if (fp1 == NULL || fp2 == NULL || fp3 == NULL) {
		puts("Could not open files");
		exit(0);
   }
	while ((c = fgetc(fp1)) != EOF)
		fputc(c, fp3);
	while ((c = fgetc(fp2)) != EOF)
		fputc(c, fp3);
	printf("files are merged");
	fclose(fp1);
	fclose(fp2);
	fclose(fp3);
	return 0;
}

Compile and Execute C++0x Onlinej

c

#include <stdio.h>
int findfileSize(char f_n[]) {
	FILE* fp = fopen(f_n, "r");
	if (fp == NULL) {
		printf("File Not Found!\n");
		return -1;
	}
	fseek(fp, 0L, SEEK_END);
	int res = ftell(fp);
	fclose(fp);
	return res;
}
int main() {
	char f_n[] = { "b.txt" };
	int result = findfileSize(f_n);
	if (result != -1)
		printf("Size of the file is %ld bytes \n", result);
	return 0;
}

Compile and Execute C++0x Onlinej

c

#include <stdio.h>
#include <string.h>

int main () {
   char src[40];
   char dest[100];
  
   memset(dest, '\0', sizeof(dest));
   strcpy(src, "This is tutorialspoint.com");
   strcpy(dest, src);

   printf("Final copied string : %s\n", dest);
   
   return(0);
}

Compile and Execute C++0x Onlinej

c

#include <stdio.h> 

int main() { 
   int arr[] = {1,2,3,4,5};  
   printf("The elements of array : "); 
   for(int i = 0; i<6; i++)
      printf(" %d",arr[i]);
   return 0; 
} 

1 2 3 4 5 6 7 ... 62 Next
Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.