Tutorialspoint

preventing array decay in C++ language

cpp

#include<iostream>
using namespace std;
void Display(int (&p)[10]) { 
   cout << "New size of array by passing reference: ";
   cout << sizeof(p) << endl;
}
int main() {
   int arr[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
   cout << "Actual size of array is: ";
   cout << sizeof(arr) <<endl;
   Display(arr);
   return 0;
}

string in C language

c

#include <stdio.h>
#include <string.h>
int main () {
   char s1[10] = "Hello";
   char s2[10] = "World";
   int  len, com ;
   strcpy(s1, s2);
   printf("Strings s1 and s2 :  %s\t%s\n", s1, s2 );
   strcat( s1, s2);
   printf("String concatenation:   %s\n", s1 );
   len = strlen(s1);
   printf("Length of string s1 :  %d\n", len );
   com = strcmp(s1,s2);
   printf("Comparison of strings s1 and s2 :  %d\n", com );
   return 0;
}

C++ arrays

cpp

#include <stdio.h>
int main () {
   int a[5];
   int i,j;
	
   for (i=0;i<5;i++) {
      a[i] = i+10; 
   }
   for (j=0;j<5;j++) {
      printf("Element[%d] = %d\n", j, a[j] );
   }
   return 0;
}

C Language Arrays

c

#include <stdio.h>
int main () {
   int a[5];
   int i,j;
	
   for (i=0;i<5;i++) {
      a[i] = i+100; 
   }
   for (j=0;j<5;j++) {
      printf("Element[%d] = %d\n", j, a[j] );
   }
   return 0;
}

while loop in C language

c

#include <stdio.h>
int main () {
   int a = 5;

   while( a < 10 ) {
      printf("Value of a: %d\n", a);
      a++;
   }
   return 0;
}

for loop in C language

c

#include <stdio.h>
int main () {
   int a = 5;

   for(int i=0;i<=5;i++) {
      printf("Value of a: %d\n", a);
      a++;
   } 
   return 0;
}

C language Break Statement

c

#include <stdio.h>
int main () {
   int a = 50;

   while( a < 60 ) {
      if( a == 55) {
         break;
      }
      printf("Value of a: %d\n", a);
      a++;
   }
   return 0;
}

C language Continue Statement

c

#include <stdio.h>
int main () {
   int a = 50;

   do {
      if( a == 55) {
         a = a + 1;
         continue;
      }
      printf("Value of a: %d\n", a);
      a++;
   } while( a < 60 );
   return 0;
}

C language goto statement

c

#include <stdio.h>
int main () {
   int a = 10;

   LOOP:do {
      if( a == 12) {
         a = a + 1;
         goto LOOP;
      }
      printf("Value of a: %d\n", a);
      a++;
   }while( a < 15 );
   return 0;
}

double in C language

c

#include<stdio.h>
#include<string.h>
int main() {
   float x = 10.327;
   double y = 4244.546;
   int z = 28;
   printf("The float value : %f\n", x);
   printf("The double value : %f\n", y);
   printf("The sum of float,</p> double and int variable : %f\n", (x+y+z));
   return 0;
}

Previous 1 ... 4 5 6 7 8 9 10 ... 1808 Next
Advertisements
Loading...