Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Pointer Part 2-Computer Fundamentals-Lab Codes, Exercises of Computer Fundamentals

The course covers important and advance elements of C and C plus plus programming language. This course provides the student with the skills required to design, code, and test and execute programs of simple to intermediate complexity. It includes: Prototype, Function, Print, Pointer, Array, Size, Initialization, Value, Printf, Memory

Typology: Exercises

2011/2012

Uploaded on 07/31/2012

karthik
karthik 🇮🇳

4.6

(17)

100 documents

1 / 2

Toggle sidebar

Related documents


Partial preview of the text

Download Pointer Part 2-Computer Fundamentals-Lab Codes and more Exercises Computer Fundamentals in PDF only on Docsity! #include <stdio.h> #include <stdlib.h> /* prototype of function print that accept a pointer to pointer (in other words * 2D array */ void print(int **ar, int r, int c); int main() { int r=3,c=5,i,j; // int a1[2][4]={{1,2,3,4},{5,6,7,8}}; int **aptr; // pointer to pointer // initializing arrays of pointer of size r aptr=(int*)malloc(r*sizeof(int*)); for(i=0;i<r;i++) { aptr[i]=(int)malloc(c*sizeof(int)); // initializing each pointer with array size of c of interger } printf("Done with initializing \n\n\n"); for (i=0;i<r;i++) { for(j=0;j<c;j++) { aptr[i][j]=rand()%20; } } printf("Done with initialization Value \n\n\n"); for (i=0;i<r;i++) { for(j=0;j<c;j++) { printf( "aptr[ %d ][ %d ] = %d\n",i ,j,aptr[i][j] ); } } printf("Going in to function \n\n\n"); print(aptr,r,c); printf("Coming out of function \n\n\n"); /* * Should free memory at the end of the program or when no more required */ for(i=0;i<r;i++) { free(aptr[i]); } free(aptr); docsity.com
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved