C and C++ Programs

C and C++ Programs

It Contains C And C++ programs that are useful for students it includes C programs for data structures

Sorted by: Top Picks
Written by SKumar07 on
I thought the following program was a perfect C program. But on compiling, I found a silly mistake. Can you find it out (without compiling the program :-) ? #include void OS_Solaris_print () { printf ( "Solaris - Sun Microsystems \n " ); } void OS_Windows_print () { printf ( "Windows - Microsoft \n " ); } void OS_HP-UX_print () { printf ( "HP-UX - Hewlett Packard \n " ); } int main () { int num ; printf ( "Enter the number (1-3): \n " ); scanf ( " %d " , & num ); switch ( num ) { case 1 : ... Read Full Story
Written by huntgeorge27 on
Function Arguments If a function is to use arguments, it must declare variables that accept the values of the arguments. These variables are called the formal parameters of the function . They behave like other local variables inside the function and are created upon entry into the function and destroyed upon exit. As shown in the following function , the parameter declarations occur after the function name: /* Return 1 if c is part of string s; 0 otherwise. */ int is_in(char *s, char c) { while(*s) if(*s==c) return 1; else s++; return 0; } The function is_in() has two parameters: s and c ... Read Full Story
Written by huntgeorge27 on
Returning Pointers Although functions that return pointers are handled just like any other type of function , a few important concepts need to be discussed. Pointers to variables are neither integers nor unsigned integers. They are the memory addresses of a certain type of data. The reason for this distinction is because pointer arithmetic is relative to the base type. For example, if an integer pointer is incremented, it will contain a value that is 4 greater than its previous value (assuming 4-byte integers). In general, each time a pointer is incremented (or decremented), it points to the next (or previous) item of its ... Read Full Story
Written by huntgeorge27 on
Pointers to Functions A particularly confusing yet powerful feature of C++ is the function pointer. Even though a function is not a variable , it still has a physical location in memory that can be assigned to a pointer . This address is the entry point of the function and it is the address used when the function is called. Once a pointer points to a function, the function can be called through that pointer . Function pointers also allow functions to be passed as arguments to other functions. You obtain the address of a function by using the function’s name without any parentheses ... Read Full Story
Written by huntgeorge27 on
Initializing Pointers After a local pointer is declared but before it has been assigned a value, it contains an unknown value. (Global pointers are automatically initialized to null.) Should you try to use the pointer before giving it a valid value, you will probably crash your program—and possibly your computer’s operating system as well—a very nasty type of error! There is an important convention that most C / C++ programmers follow when working with pointers: A pointer that does not currently point to a valid memory location is given the value null (which is zero). By convention, any pointer that is null implies that ... Read Full Story
Sponsors
Sorted by: Top Rated
Click to play video
Sorted by: Top Rated
No pictures yet.
Sorted by: Top Rated
No entries yet.
More From Zimbio
Copyright © 2009 - Zimbio, Inc. Some rights reserved.