0% found this document useful (0 votes)
17 views4 pages

2D Array

The document contains multiple C programming code snippets that demonstrate various concepts such as array manipulation, pointer arithmetic, and string handling. Each code snippet has a specific focus, including printing addresses, accessing elements, and using command-line arguments. The final sections discuss the getline() function and its implementation in C.

Uploaded by

surya765123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

2D Array

The document contains multiple C programming code snippets that demonstrate various concepts such as array manipulation, pointer arithmetic, and string handling. Each code snippet has a specific focus, including printing addresses, accessing elements, and using command-line arguments. The final sections discuss the getline() function and its implementation in C.

Uploaded by

surya765123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Predict the output

1 . int main() { static unsigned int arr[3][4]={{11,22,33,44},{55,66,77},{88,99}};

printf(“arr=%u\n”, arr);

printf(“%u %u\n”,*arr, **arr);

printf(“%u %u %u\n”,arr+1, *arr+1, *(arr+1));

printf(“%u %u %u\n”,arr[1]+1,*arr[1]+1,arr[1][1]+1);

2. int main()
{
static int a[]={0,1,2,3,4};//consider the starting address of this array is 5000
static int *p[]={a,a+1,a+2,a+3,a+4};//consider the starting address of this array is 5100
int **ptr;
ptr=p;
**ptr++;
printf("%d %d %d",ptr-p,*ptr-a,**ptr);
*++*ptr;
printf("%d %d %d",ptr-p,*ptr-a,**ptr);
++**ptr;
printf("%d %d %d",ptr-p,*ptr-a,**ptr);
}

3. int main(){ static char arr[][10]={“int”, “char”, “float”, “void”, “double”}

printf(“arr=%u %s\n”, arr,arr);

printf(“%s %s\n”,arr[0], *arr);

printf(“%s %s %s\n”, *arr+1, *(arr+1), arr[1]+1);

printf(“%c %c %c\n”, **arr+1, *arr[1]+1, arr[1][1]+1);

4. int main(){ static char arr[][10]={“int”, “char”, “float”, “void”, “double”}

printf(“%s\n”, ????);//how to print “oat” from float

printf(“%c \n”, ??? );//how to print ‘b’ from double.

}
5. int main(){ static unsigned int arr[][4]={{11,22,33,44},{55,66,77},{88,99}};

int (*p)[4]; int (*q)[3]; int (*r)[5]; int **s;

p=q=r=s=arr;

printf(“%u %u %u %u %u\n”,arr, p, q, r, s);

printf(“%u %u %u %u %u\n”, arr+1, p+1, q+1, r+1, s+1);

printf(“%u %u %u\n”,**arr,arr[1][1],arr[2][1]);

printf(“%u %u %u\n”,**p,p[1][1],p[2][1]);

printf(“%u %u %u\n”,**q,q[1][1],q[2][1]);

printf(“%u %u %u\n”,**r,r[1][1],r[2][1]);

printf(“%u %u %u\n”,**s,s[1][1],s[2][1]);

6. int main() {

char **p;

char *q[5];

char (*r)[5];

printf(“%lu %lu %lu\n”,sizeof(p), sizeof(*p),sizeof(**p));

printf(“%lu %lu %lu\n”,sizeof(q), sizeof(*q),sizeof(**q));

printf(“%lu %lu %lu\n”,sizeof(r), sizeof(*r),sizeof(**r));

7. int main(){

char *arr[]={“long”, “short” , “unsigned”, “signed”};

printf(“%lu %lu %lu\n”, sizeof(arr),sizeof(*arr), sizeof(**arr));

printf(“%lu %lu\n”, arr, arr+1);

printf(“%lu %lu\n”, arr[1],arr[1]+1);

}
8. int main(){ char str[][10]={“hello”, “vector”, “hyderabad”};

char *arr[]={“HELLO”, “VECTOR”, “HYDERABAD”};

char (*p)[10]=str; char **q=arr;

printf(“%lu %lu\n”, str, p);

printf(“%s %s\n”, str[1], p[1]);

printf(“%c %c\n”, str[2][1], p[2][1]);

printf(“%lu %lu\n”, arr, q);

printf(“%s %s\n”, arr[1], q[1]);

printf(“%c %c\n”, arr[2][1], q[2][1]);

9. main() {

int i,argc;

i=argc=3;

char *arg[3]={ "abcde "," fghij" ," klmno " };

char **argv=arg;

while(++argv,--argc,--i)

printf("%s",*argv);

10. int main(int argc ,char *argv[]) {

if(argc==1) { printf("error"); exit(1); }

while(**argv,--argc) {

printf("%s ", *++argv);

What is the output for this program is if input is $ ./a.out sun run
11. int main(int argc ,char *argv[]) {

if(argc==1) { printf("error"); exit(1); }

while(**argv,--argc) {

while(argc,**argv) {

printf("%c",*(*argv)++);

putchar(‘ ‘);

What is the output for this program is if input is $ ./a.out sun run

12. Learn the getline() function using manual. Use it to input a string. Implement an user-defined
getline function.

You might also like