Tuesday, June 19

Pointers (Lecture Notes) : CUSAT s1s2 Questions




Hi friends,

Here I'm posting some important concepts asked in CUSAT B Tech S1 S2 C programming examination. All the concepts are descried here in very briefly so that you can grasp it quickly.
Here we go..!!! :)



Pointer

· Pointer is a variable that represents the location of a data item.

· Address operator (&) : It evaluates the address of its operand.

· Indirection Operator(*): Used to access data item referenced by a pointer.

Example:

Main()

{

Int a=3;

Int *ptr;

Ptr=&a;

Printf(“%d %u” , *ptr, ptr);

}

Pointer to an array

· A pointer can be used to reference an array.

· The name of an array will work as the pointer to its first element.

Main()

{

Int a[]= { 1, 2 , 3, 4};

Int *ptr =a;

For(int i=0; i<4;i++)

{

Printf(“%d”,* ptr+i);

}

Arrays of Pointers

· A group of pointers are stored in an array.

· Arrays of pointers can be used to store multidimensional arrays

Datatype *array[size];

Structures:

· A collection of heterogeneous elements.

· In structure memory will be allocated for each element.

Struct student {

Char name[20];

Int mark;

};

Union

· Similar to structures, A collection of heterogeneous elements.

· Memory will be allocated for largest member only. Other members have to share this memory.

union student {

Char name[20];

Int mark;

};





4 comments :

Anonymous said... Best Blogger Tips [Reply to comment] Best Blogger Templates

upload more pointer concepts please

v!p!n said... Best Blogger Tips [Reply to comment] Best Blogger Templates

Definitely.. please keep in touch.!! :)

Anonymous said... Best Blogger Tips [Reply to comment] Best Blogger Templates

can you please include program outputs?

v!p!n said... Best Blogger Tips [Reply to comment] Best Blogger Templates

Sure @Anonymous.!!

Post a Comment