Access in cpp classes

When a base class is inherited as private, all public and protected members of that class become private members of the derived class. However, in certain circumstances, you may want to restore one or more inherited members to their original access specification. For example, **you might want to grant certain public members of the base class public status in the derived class even though the base class is inherited as private. [Read More]

Escape characters and printf

Escape Sequence

Character represented

\n

newline

\t

tab

\\

backslash itself

\’

quote ``’’’

\”

double quote ``”’’

For example,

printf("\\t\\"My name is \\'%s\\'\\"\\n", "Jim");  

```Which prints  
  

“My name is ‘Jim’”

I/O in c without printf and scanf.

Problem I/O in c without printf and scanf. Method 1 - getchar and putchar int getchar(); int putchar(int value); Sample Program #include <stdio .h> int main(void) { int c; while ((c = getchar()) != EOF) { putchar(c); } return 0; } Note the use of parentheses. c=gethar()!=EOF implies whether c = 0 or 1 depending on whether character get is not EOF or is EOF. EOF is 257 , so use int rather than char. [Read More]

C preprocessor

The C preprocessor (cpp) is the preprocessor for the C programming language. In many C implementations, it is a separate program invoked by the compiler as the first part of translation. The preprocessor handles directives for source file inclusion (#include), macro definitions (#define), and conditional inclusion (#if). The language of preprocessor directives is not strictly specific to the grammar of C, so the C preprocessor can also be used independently to process other types of files. [Read More]

Complicated Declaration

Function Declaration

Function

Returning

Accepting

int *f();

int ptr

any number of arg in c and no arg in cpp

char(*(*f())[10])();

pointer to the array of pointers to function

int (*(*f())[10]) ()

pointer to the array of 10 pointers to function that returns integer

Pointer

Expression

p is the pointer to

int *p;

iint **p;

int (*p)();

function that returns the integer

int (*p)[30]

array of 30 int

Program string class

Program String Class(Source Code) // Program Ch03pr06 // Program string class #include #include #include class string { private :  char *str ;  public :  string( ) ; string ( char *s ) ; string ( string& s ) ; int length( ) ; char operator [] ( int index ) ; void operator = ( string s ) ; string operator + ( string s ) ; [Read More]

Pattern matching program using Brute Force Algorithm

Pattern matching program using Brute Force Algorithm(Source Code) // Program Example Ch03pr05 // Pattern matching program using Brute Force Algorithm #include #include #include const int MAX = 20 ; class string { private :  char str[MAX] ;  public :  string( ) ; string ( char *s ) ; static int xstrsearch ( string &s1, string &s2 ) ; void show( ) ; } ; // initializes data [Read More]

Program to manage array of pointers to strings

Program to manage array of pointers to strings (Source Code) // Program Ch03pr04 // Program to manage array of pointers to strings #include #include #include const int MAX1 = 6 ; const int MAX2 = 10 ; class string { private :  char *names[MAX1] ; int count ;  public :  string( ) ; int add( ) ; void show( ) ; ~string( ) ; } ; // allocates the memory [Read More]

Program with the use of array of pointers to strings

Program with the use of array of pointers to strings(Source Code) // Program: Ch03pr03 // Program with the use of array of pointers to strings #include #include #include const int MAX = 6 ; class string { private :  char *names[MAX] ; int count ;  public :  string( ) ; int add ( char *s ) ; void swap ( int i, int j ) ; void show( ) ; [Read More]

Program to manage a 2-D array of Characters

Program to manage a 2-D array of Characters(Source Code) // Program Ch03pr02 // Program to manage a 2-D array #include #include const int MAX1 = 6 ; const int MAX2 = 10 ; class string { private :  char masterlist[MAX1][MAX2] ; int count ;  public :  string( ) ; int add ( char *s ) ; int find ( char *s ) ; } ; // initialises the data [Read More]