background preloader

CProgramming

Facebook Twitter

String Sets

Printf. Function int printf ( const char * format, ... ); Print formatted data to stdout Writes the C string pointed by format to the standard output (stdout). If format includes format specifiers (subsequences beginning with %), the additional arguments following format are formatted and inserted in the resulting string replacing their respective specifiers. Parameters format C string that contains the text to be written to stdout. A format specifier follows this prototype: [see compatibility note below] %[flags][width][.precision][length]specifier Where the specifier character at the end is the most significant component, since it defines the type and the interpretation of its corresponding argument: The format specifier can also contain sub-specifiers: flags, width, .precision and modifiers (in that order), which are optional and follow these specifications: The length sub-specifier modifies the length of the data type.

Note: Yellow rows indicate specifiers and sub-specifiers introduced by C99.

Pointers

C dereferencing pointer - C Programming. Dereferencing Pointer in C Programming Language : Asterisk(*) indirection operator is used along with pointer variable while Dereferencing the pointer variable.Asterisk Operator is also called as value at operatorWhen used with Pointer variable, it refers to variable being pointed to,this is called as Dereferencing of Pointers What is Dereferencing Pointer ? Dereferencing Operation is performed to access or manipulate data contained in memory location pointed to by a pointerAny Operation performed on the de-referenced pointer directly affects the value of variable it pointes to.

Live Example : Dereferencing Pointer // Sample Code for Dereferencing of Pointerint n = 50 , x ; int *ptr ; // Un-initialized Pointer ptr = &n; // Stores address of n in ptr x = *ptr; // Put Value at ptr in x Evaluation : // Sample Code for Dereferencing of Pointer *(ptr) = value at (ptr) = value at (2001) = 50 //Address in ptr is nothing but address of n Summary :

Arrays

Implementing a dynamically sized array in C | Happy Bear Software | Web Application Development. One of the biggest stumbling blocks on moving to C from a high-level scripting language comes when you realize you need to know how big an array needs to be before you use it. In this article I'm going to go through a quick implementation of a dynamically sized array in C. Not only will this give us a useful bit of library code in C, it will also help to illustrate the sort of performance/memory overhead in higher level languages have to pay down to give users access to built-in variable-length arrays. Basic C arrays Here's a quick refresher on what a basic C array looks like, allocated on the stack: int main() { // Declare an array of 3000 integers int my_array[3000];} This bit of code does the following: Allocates memory on the stack1.

Based on the above, it's clear that C arrays are for the most part syntactic sugar working with its underlying memory handling operations. There's no easy way to automatically resize an array as its contents expand. You can index out of array bounds. N.B.

Structs

C - Returning a struct pointer. Untitled. Programming in C. A. D. Marshall 1994-2005 Substantially Updated March 1999 Next: Copyright Keyword Searcher Click Here to Download Course Notes. Direct link to Java Algorithm Animations (C related) Lecture notes + integrated exercises, solutions and marking Useful Links C tutorial for reference for beginners About this document ...

Programming in C.