Computer Science, asked by henry3068, 11 months ago

Give keywords introduced by language c++ which are not in c language

Answers

Answered by padmesh07
0
Listed below are some features that are found in C++, not found in C, but still have nothing to do with Object Oriented Programming.

Casts

In C, if you want to cast an int to a long int, for example, you'd use int i=0; long l = (long) i; In C++, you can use a function-like call to make the cast. long l = long(i); It's easier to read. Since it's possible to create functions to perform casts involving user-defined types, this makes all the casts look consistent. For example, you may have a user-defined type -- complex numbers. You have a function that accepts an integer and casts it to a complex number: 1 --> 1 + 0i (real part is 1 and imaginary part is 0) Suppose your function call is named 'complex', then it may look like: Complex x; int i=1; x = complex(i);

Flexible Declarations

In C, all var declarations within a scope occur at the beginning of that scope. Thus, all global declartions must appear before any functions, and any local declarations must be made before any executable statements.

C++, on the other hand, allows you to mix data declarations with functions and executable statements. E.g. In C,

void makeit(void) { float i; char *cp; /* imagine 2000 lines of code here */ /* allocate 100 bytes for cp */ cp = malloc(100); /* 1st use of cp */ for (i=0; i<100; ++i) /* 1st use of i */ { /* do something */ } /* more code */ } In C++, void makeit(void) { // 2000 lines of code char *cp = new char[100]; for (int i=1; i<10; i++) { } }

'struct' and 'union' Tags

In C, we would have this segment: struct foo {int a; float b;} struct foo f; This declares a struct with the tag name 'foo' and then creates an instance of foo named f. Notice when you declare var of that struct, you have to say 'struct foo'. In C++, struct and union tags are considered to be type name, just as if they had been declared by the 'typedef' statement. struct foo {int a; float b;} foo f; which is equivalent to the following in C: typedef struct { int a; float b; } foo; foo f;
Answered by kavaysharma2007
0

Answer:

Listed below are some features that are found in C++, not found in C, but still have nothing to do with Object Oriented Programming.

Casts

In C, if you want to cast an int to a long int, for example, you'd use

        int i=0;

        long l = (long) i;

In C++, you can use a function-like call to make the cast.

        long l = long(i);

It's easier to read. Since it's possible to create functions to perform casts involving user-defined types, this makes all the casts look consistent. For example, you may have a user-defined type -- complex numbers. You have a function that accepts an integer and casts it to a complex number:

        1 --> 1 + 0i (real part is 1 and imaginary part is 0)

Suppose your function call is named 'complex', then it may look like:

        Complex x;

        int i=1;

        x = complex(i);

Flexible Declarations

In C, all var declarations within a scope occur at the beginning of that scope. Thus, all global declartions must appear before any functions, and any local declarations must be made before any executable statements.

C++, on the other hand, allows you to mix data declarations with functions and executable statements. E.g. In C,

        void makeit(void)

        {

           float i;

           char *cp;

           /* imagine 2000 lines of code here */

           /* allocate 100 bytes for cp */

           cp = malloc(100);    /* 1st use of cp */

           for (i=0; i<100; ++i)      /* 1st use of i */

           {

              /* do something */

           }

           /* more code */

        }

In C++,

        void makeit(void)

        {

           // 2000 lines of code

           char *cp = new char[100];

           for (int i=1; i<10; i++)

           {

           }

        }

'struct' and 'union' Tags

In C, we would have this segment:

        struct foo {int a; float b;}

        struct foo f;

This declares a struct with the tag name 'foo' and then creates an instance of foo named f. Notice when you declare var of that struct, you have to say 'struct foo'. In C++, struct and union tags are considered to be type name, just as if they had been declared by the 'typedef' statement.

        struct foo {int a; float b;}

        foo f;

which is equivalent to the following in C:

        typedef struct

                {

                    int a;

                    float b;

                } foo;

        foo f;

'const'

In ANSI C, it also supports 'const', but C++'s 'const' is more flexible than C's. In both C and C++, a value declared as 'const' is inviolate; it may not be modified by any part of the program in any way. The most common use of 'const' values in C is to replace '#define' literal constants.

        #define MAX_CUSTOMERS   10

        const int MAX_CUSTOMERS = 10;

Thus,

        MAX_CUSTOMERS = 10;

        MAX_CUSTOMERS ++;

are both not acceptable. Note: since you cannot make changes to a 'const', each constant must be initialized when declared. The following is wrong:

        const int invalid;

In C++, you can do something like

        const int ArraySize = 100;

        int Array[ArraySize];

while in ANSI C, this would be flagged as an error.

More examples for 'const':

        const int v[] = {1, 2, 3, 4};

        const char* pc = "asdf";   // pointer to constant

        pc[3] = 'a';               // error

        pc = "ghjk";               // ok

        char *const cp = "asdf";   // constant pointer

        cp[3] = 'a';               // ok

        cp = "ghjk";               // error

        const char *const cpc = "asdf";  // const pointer to const

        cpc[3] = 'a';                    // error

        cpc = "ghjk";                    // error

Function call:

        char* strcpy (char* p, const char*q);  // cannot modify *q

Here, by declaring a pointer argument const, the function is prohibited from modifying the object pointed to, which makes perfect sense since strcpy copies q to p and you better preserve q.

The :: Operator

Explanation:

hope it helps

pls mark it as brainliest

Similar questions