Posts

Showing posts from April, 2017

Pointers to Structures in c

#include <stdio.h> #include <string.h> struct Books {    char  title[50];    char  author[50];    char  subject[100];    int   book_id; }; /* function declaration */ void printBook( struct Books book ); int main( ) {    struct Books Book1;        /* Declare Book1 of type Book */    struct Books Book2;        /* Declare Book2 of type Book */    /* book 1 specification */    strcpy( Book1.title, "C Programming");    strcpy( Book1.author, "ramratan bissoo");    strcpy( Book1.subject, "C Programming Tutorial");    Book1.book_id = 654123;    /* book 2 specification */    strcpy( Book2.title, "Miracle Billing");    strcpy( Book2.author, "DEEPAK SHARMA");    strcpy( Book2.subject, "Miracle Billing Tutorial");    Book2.book_id = 420420; ...

Structures as Function Arguments

#include <stdio.h> #include <string.h> struct Books {    char  title[50];    char  author[50];    char  subject[100];    int   book_id; }; /* function declaration */ void printBook( struct Books book ); int main( ) {    struct Books Book1;        /* Declare Book1 of type Book */    struct Books Book2;        /* Declare Book2 of type Book */    /* book 1 specification */    strcpy( Book1.title, "C Programming");    strcpy( Book1.author, "ramratan bissoo");    strcpy( Book1.subject, "C Programming Tutorial");    Book1.book_id = 654123;    /* book 2 specification */    strcpy( Book2.title, "Miracle Billing");    strcpy( Book2.author, "DEEPAK SHARMA");    strcpy( Book2.subject, "Miracle Billing Tutorial");    Book2.book_id = 420420; ...

string copy in c

#include <stdio.h> #include <string.h> int main () {    char str1[12] = "Hello";    char str2[12] = "World";    char str3[12];    int  len ;    /* copy str1 into str3 */    strcpy(str3, str1);    printf("strcpy( str3, str1) :  %s\n", str3 );    /* concatenates str1 and str2 */    strcat( str1, str2);    printf("strcat( str1, str2):   %s\n", str1 );    /* total lenghth of str1 after concatenation */    len = strlen(str1);    printf("strlen(str1) :  %d\n", len );    return 0; } output:-- strcpy( str3, str1) :  Hello strcat( str1, str2):   HelloWorld strlen(str1) :  10

The static Storage Class

#include <stdio.h> /* function declaration */ void func(void); static int count = 5; /* global variable */ main() {    while(count--) {       func();    }    return 0; } /* function definition */ void func( void ) {    static int i = 5; /* local static variable */    i++;    printf("i is %d and count is %d\n", i, count); } output is i is 6 and count is 4 i is 7 and count is 3 i is 8 and count is 2 i is 9 and count is 1 i is 10 and count is 0

Global Variables

#include <stdio.h> /* global variable declaration */ int g; int main () {   /* local variable declaration */   int a, b;   a = 10;   b = 20;   g = a + b;   printf ("value of a = %d, b = %d and g = %d\n", a, b, g);   return 0; } OUTPUT:- value of a = 10, b = 20 and g = 30

Local Variables

#include <stdio.h> int main () {   /* local variable declaration */   int a, b;   int c;   /* actual initialization */   a = 10;   b = 20;   c = a + b;   printf ("value of a = %d, b = %d and c = %d\n", a, b, c);   return 0; } OUTPUT:-- value of a = 10, b = 20 and c = 30

Calling a Function

#include <stdio.h> /* function declaration */ int max(int num1, int num2); int main () {    /* local variable definition */    int a = 100;    int b = 200;    int ret;    /* calling a function to get max value */    ret = max(a, b);    printf( "Max value is : %d\n", ret );    return 0; } /* function returning the max between two numbers */ int max(int num1, int num2) {    /* local variable declaration */    int result;    if (num1 > num2)       result = num1;    else       result = num2;    return result; } output:-- Max value is : 200

The Infinite Loop

#include <stdio.h> int main () {    for( ; ; ) {       printf("This loop will run forever.\n");    }    return 0; }

Variable Declaration in C

#include <stdio.h> // Variable declaration: extern int a, b; extern int c; extern float f; int main () {    /* variable definition: */    int a, b;    int c;    float f;    /* actual initialization */    a = 10;    b = 20;      c = a + b;    printf("value of c : %d \n", c);    f = 70.0/3.0;    printf("value of f : %f \n", f);    return 0; } output is value of c : 30 value of f : 23.333334

bacis of cpp

C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC PDP-11 computer in 1972. In 1978, Brian Kernighan and Dennis Ritchie produced the first publicly available description of C, now known as the K&R standard. The UNIX operating system, the C compiler, and essentially all UNIX application programs have been written in C. C has now become a widely used professional language for various reasons − Easy to learn Structured language It produces efficient programs It can handle low-level activities It can be compiled on a variety of computer platforms

wellcome c language

wellcome my blog we provaid c language program in simple and best programming