UNIT 1 UNIT 2 UNIT 3 UNIT 4 UNIT 5 UNIT 6 UNIT 7 UNIT 8
Home Online Quiz Lab Programs Previous Questions Resources Glossary Syllabus Faculty Team

Latest News

Lesson PPTs have been uploaded to Resources Section.


Teaching material,Tutorials and Practice problems of all UNIT's are added.


ebooks have been uploaded to Resources Section.



UNIT 3


TOPICS TO BE COVERED IN THIS UNIT:

  1. Arrays- concepts, declaration, definition, accessing elements, storing elements
  2. Arrays and Functions
  3. Two-dimensional and multi-dimensional arrays
  4. Applications of arrays
  5. Pointers- concepts, initialization of pointer variables
  6. Pointers and function arguments
  7. Address arithmetic
  8. Character pointers and functions
  9. Pointers to Pointers
  10. Pointers and multidimensional arrays
  11. Dynamic memory managements functions
  12. Command line arguments


TEACHING MATERIAL

Unit 3 Teaching Aids - Click Here


TUTORIAL MATERIAL

Tutorial 1


  1. Consider the array definition
    int num[10]={3,3,3};
    
    Pick the correct answer:

    1. num[9] is the last element of the array num
    2. the value of num[8] is 3
    3. the value of num[3] is 3
    4. all the above

  2. The following program fragment
    int  n[5][5],i,j,X[5][5];
    for(i=0;i<5;++i)
       for(j=0;j<5;j++)
         X[i][j]=n[j][i];
    
    What is resultant matrix of X.?

    1. transposes the matrix
    2. symmetric matrix
    3. does not alter the matrix
    4. none

  3. Consider the statement
    int  val[2][4]={1,2,3,4,5,6,7,8}; 
    4 will be the value of ?

    1. val[1][4]
    2. val[0][3]
    3. val [1][1]
    4. none

  4. If two dimensional array is used as a formal parameter, then
    1. both the subscripts may be left empty
    2. the first(row) subscript may be left empty
    3. the first subscript must be left empty
    4. both subscripts must be left empty

  5. The default parameter passing mechanism of an array is
    1. call by value
    2. call by reff
    3. call by value result
    4. none

  6. int main()
        {
          static int x[]={1,2,3,4,5,6,7,8};
          int i, X[ 8];
          for(i=2;i<6;++i)
          X[x[i]]=x[i];
          for(i=0;i<8;++i)
          printf("%d",X[i]);
        }

    The output of the above program is

    1. 1 2 3 4 5 6 5 7 8
    2. 1 2 3 4 5 6 7 8
    3. 8 7 6 5 4 3 2 1
    4. some garbage values


Tutorial 2



  1. If m and n have been declared as integers and p1 and p2 as pointers to integers then state if any errors in the following statements :
    1. p1=&m;
    2. p2=n;
    3. *p1=&n;
    4. p2=&*&m;
    5. m=p2-p1;
    6. p1=&p2;
    7. m=*p1+*p1++;

  2. State whether each of the following statements is true (or) false (T/F)Give reasons.
    1. An integer can be added to a pointer [ ]
    2. A pointer can never be subtracted from another pointer [ ]
    3. When an array is passed as an argument to a function, a pointer is passed [ ]
    4. Pointers can not be used as formal parameters in headers to function definition [ ]
    5. value of a local variable in a function can be changed by another function [ ]

  3. int  a, b,*ptr;
    ptr=&a;
    a=9;
    b=*ptr;
    a++;
    what is the value of a______b_______*ptr________?

  4. int a,b,*ptr;
    a=9;
    ptr=&a;
    b=*ptr;
    a++;
    what is the value of a______b_______*ptr________?

  5. int a,b,*ptr;
    a=9;
    ptr=&a;
    b=*ptr;
    *ptr+=2;
    what is the value of a______b_______*ptr________?

  6. int  a,b,*ptr;
    a=9;
    ptr=&a;
    b=*ptr;
    ptr=&b;
    ++b;
    what is the value of a______b_______*ptr________?


Tutorial 3



  1. int  main()
         {
           int  a,*b=&a, **c=&b;
           a=5;
           **c=15;
           *b=**c;
           clrscr();
           printf("A=%d,B=%d",a,*b);
         }
    1. A=15,B=15
    2. A=15,B=5
    3. A=15,B=16
    4. none

  2. main()
    {
      int a1,a2,c=3,*pt;
      pt=&c;
      a1=3*(c+5);
      a2=3*(*pt+5);
      printf("A=%d,B=%d",a1,*pt);
    }
    1. A=24,B=24
    2. A=12,B=24
    3. A=12,B=12
    4. none

  3. Which of these are reasons for using pointers?
    1. To manipulate parts of an array
    2. To refer to keywords such as for and if
    3. To return more than one value from a function
    4. To refer to particular programs more conveniently

  4. Which of the following is the correct way of declaring a float pointer?
    1. float ptr ;
    2. float *ptr ;
    3. *float ptr
    4. None of the above

  5. By the following declaration int a[10];

    Which of the following is correct?

    1. &a == a
    2. &a == a[0]
    3. a == &a[0]
    4. a != &a[0]


Tutorial 4



  1. int s[5] is a one-dimensional array of integers, which of the following refers to the third element in the array?
    1. *( s + 2 )
    2. *( s + 3 )
    3. s + 3
    4. s + 2

  2. If an array arr contains n elements, then write a program to check if arr[0] = arr[n-1], arr[1] = arr[n-2] and so on.

  3. Find the smallest number in an array using pointers.

  4. Which of the following must be used to implement pass by reference (pass by address)?
    1. structure
    2. union
    3. array
    4. pointer

  5. ____ operator is used to access a member of a structure using a pointer to structure ?
    1. *
    2. .
    3. >
    4. ->

  6. What is the output of the following program?
    	main()
    	{
          	  int a[10];
     	  scanf("%d"',a);
     	  printf("%d",*a);
    	}
    1. Compilation error as array name is used in scanf()
    2. Takes a value from user and displays it. The value is stored in 0th element of the array
    3. Takes a value from user and displays the address of that value but not the value
    4. None of the above

  7. Which function can be used to read a single character from user?
    1. getchar()
    2. fgetc()
    3. get()
    4. All there above



PRACTICE PROBLEMS

Beginner Problems


  1. What is the result of the following code segment?
  2. 	main()
    	{
        	 int  a[5]={10,20,30};
        	 printf("%d",a[3]+a[4]);
    	}
    
  3. write a program to reverse the given string.
  4. Write a program to find smallest and largest values in the array.
  5. What is the output of the following segment ?
  6. 	  main()
        	{
          	int i=0,a[5];
          	a[i]=i++;
         	printf("%d",a[i]);
       	}
    
  7. What is the output of the following segment?
  8.      main()
         {
            int a[5]={1,2,3,4,5},i;
            for(i=0;i<5;i++);
            printf("%d",a[i]);
          }
    
  9. Write a program to swap two numbers using pointers.
  10. Write a program to read a string and print it in alphabetical order.

Intermediate Problems


  1. Write a program to generate the Fibonacci series.
  2. Write a program to add two matrices.
  3. Write a program to multiply two matrices.
  4. Write a program to transpose a given matrix.
  5. write a program to reverse the given string without using string library functions.
  6. Write a program to find the sum of elements in the array using pointers.
  7. Write a program to compare two strings without using string library functions.
  8. Write a program to print the sum of the upper triangle and lower triangle.

Advanced Problems


  1. Write a program to print the given number in words. (eg: if n=123 then the output will be one hundred and twenty three).
  2. Write a program to generate the first n terms of Fibonacci series using command line arguments.
  3. Write a program to find whether the given string is palindrome or not without using string library functions.
  4. Write a program to extract a substring from a given string.
  5. Write a program to create a matrix of size m*n. Find the sum of each row and each column and if it is a square matrix then the sum of the diagonal elements also.

This Page Is Designed By Akash Jain

Copyright (c) Aditya Engineering Colleges, Surampalem. All rights reserved.
Development Team