Monthly Archive: June 2010

Program to copy the contents of one array into another in the reverse order 7

Program to copy the contents of one array into another in the reverse order

The below mentioned program copies the content of one array name ‘source’ into another array named ‘dest’ in the reverse order. In case you have any queries related to the below mentioned program, please don’t hesitate to comment on this post. Your comments are always welcomed. #include #include void main(){ int source[100], dest[100],i,j,no; clrscr(); printf(“Enter the number of elements: “); scanf(“%d”,&no); for(i=0;i<no;i++){ printf(“Enter Source Array Element%d :”,i+1); scanf(“%d”,&source[i]); } for(i=0,j=no-1;i<no;i++,j–){ dest[j]=source[i]; } printf(“Destination array:\n”); for(i=0;i<no;i++){ printf(“%d\t”,dest[i]); } getch(); } Output: Enter the number of elements: 10 Enter Source Array Element1 :1 Enter Source Array Element2 :2 Enter Source Array Element3...

Structures in C Programming Language 32

Structures in C Programming Language

Structure is a special type of C data type. Structures contains a number of data types grouped together. Structures in C is one of the excellent functionality provided in C. Structures makes C Programming language easy and simpler up to certain extent. Structure is most widely used in Programming. Structures in C allows multiple data types to be grouped together. As a programmer I have used structures in C a lot and find this feature interesting too. Just go through this article and you too will find structures in C interesting. Let us suppose you want to store basic information...

Demo on Structures in C 12

Demo on Structures in C

The Structure is a special type of C data type. A structure contains a number of data types grouped together. Structure in C allows multiple data types to be grouped together. The below mentioned program is to demonstrate structures in C Programming Language. #include #include void main(){ struct animal{ int age; char name[10]; char gender; }a[10]; int no,i; clrscr(); printf(“Enter the number of animals: “); scanf(“%d”,&no); for(i=0;i<no;i++){ printf(“\nEnter the age of animal %d: “, i+1); scanf(“%d”,&a[i].age); printf(“\nEnter the name of animal %d: “,i+1); scanf(“%s”,&a[i].name); printf(“\nEnter the gender(M/F) of animal %d: “,i+1); scanf(“%s”,&a[i].gender); } for(i=0;i<no;i++){ printf(“\n%d”,a[i].age); printf(“\t%s”,a[i].name); printf(“\t%c”,a[i].gender); } getch(); }...

Storage Classes in C Programming Language 45

Storage Classes in C Programming Language

A storage class in C is an attribute that tells us where the variable would be stored, what will be the initial value of the variable if no value is assigned to that variable, life time of the variable and scope of the variable. There are four storage classes in C: 1) Automatic storage class 2) Register storage class 3) Static storage class 4) External storage class Automatic storage class in C: The keyword used for Automatic storage class is ‘auto’. The variable declared as auto is stored in the memory. Default value of that variable is garbage value. Scope...

Pointer Operations Demo in C 12

Pointer Operations Demo in C

Here, we will demonstrate pointer operations in C programming. #include #include void main(){ int arr[5]={12,13,14,15,16}; int *ptrArr, *ptrArr1,i; clrscr(); ptrArr = arr; printf(“\nPrinting the first element of array: %d\n\n”,*ptrArr); /*Pointer variable can be increased. If added 1 to it, it will point to the next element of the same array*/ for(i=0;i<5;i++){ printf(“%d\t”, *ptrArr); ptrArr++; } printf(“\n\n”); /*Now the Pointer is pointing to a memory location that is not reserved so if you will print the value at pointer location it will print garbage and some times it show any RUN TIME error because C compiler will not check array boundaries*/...

sprintf function Demo 2

sprintf function Demo

Understand how sprintf function works in C programming language with the help of an example. Here we demonstrate sprintf function in C language. If you have any questions, do feel free to comment. #include #include void main(){ char *str; char *first=”Learn”, *second = “C”, *third=”Online”; clrscr(); sprintf(str,”%s%s%s.com is a great site”, first, second, third); printf(“%s”,str); getch(); } Output: LearnCOnline.com is a great site Also See: Explanation on sprintf function

FREE C Cheatsheet - Speed Up Your C Programming.

FREE C Cheatsheet - Speed Up Your C Programming.

Download a 7-page free cheat sheet for easy and quick access to C Concepts, Snippets, and Syntax.

Thank you! Check you inbox and access your cheat-sheet