State four arithmetic operations perform on pointer with example.

1 Answer

Answer :

The pointer arithmetic is done as per the data type of the pointer. The basic operations on pointers are

Increment:

It is used to increment the pointer. Each time a pointer is incremented, it points to the next location with respect to memory size .

Example,

If ptr is an integer pointer stored at address 1000,then ptr++ shows 1002 as incremented location for an int.It increments by two locations as it requires two bytes storage.

Decrement:

It is used to decrement the pointer. Each time a pointer is decremented, it points to the previous location with respect to memory size.

Example,

If the current position of pointer is 1002, then decrement operation ptr-- results in the pointer pointing to the location 1000 in case of integer pointer as it require two bytes storage.

Addition

When addition operation is performed on pointer, it gives the location incremented by the added value according to data type.

Eg:

If ptr is an integer pointer stored at address 1000,

Then ptr+2 shows 1000+(2*2) = 1004 as incremented location for an int.

Subtraction

When subtraction operation is performed on the pointer variable, it gives the location decremented by the subtracted value according to data type.

Eg:

If ptr is an integer pointer stored at address 1004,

Then ptr-2 shows 1004-(2*2) = 1000 as decremented location for an int. 

Related questions

Description : Write a program to accept two numbers from user and perform addition, subtraction, multiplication and division operations using pointer.

Last Answer : #include #include void main() { int no1,no2,*ptr1,*ptr2,result; clrscr(); printf("Enter no1:"); scanf("%d",&no1); printf("\nEnter no2:"); scanf("%d",&no2); ptr1=&no1; ptr2=&no2; ... "\n Multiplication=%d",result); result=*ptr1/(*ptr2); printf("\n Division=%d",result); getch(); }

Description : State the syntax to declare pointer variable with example.

Last Answer : General syntax to declare pointer. datatype *var_name; Eg: int var = 20;

Description : Give any four advantages of pointer.

Last Answer : Advantages of pointer: 1. Pointers reduce the length and complexity of a program. 2. They increase execution speed. 3. A pointer enables us to access a variable that is defined outside the ... strings results in saving of data storage space in memory. 6. It supports dynamic memory management.

Description : Explain how to pass pointer to function with example.

Last Answer : When pointer (addresses) is passed to the function as an argument instead of value then function is called as call by reference. Example: #include #include int add(int *); void main() { int *ptr,pos=0; clrscr(); printf( ... ; getch(); } int add(int *p) { int i=0; int sum=0; for(i=1;i

Description : Write a program to Print values of variables and their addresses. Note : 1) Variables can be of any data type. 2)Use of & or pointer to display address shall be considered. 

Last Answer : #include #include void main() { int a,b; clrscr(); a=5; b=10; printf("\n Value of a=%d",a); printf("\n Address of a=%u",&a); printf("\n Value of b=%d",b); printf("\n Address of b=%u",&b); getch(); }

Description : Define pointer. Write syntax for pointer declaration.

Last Answer : Definition: A pointer is a variable that stores memory address of another variable which is of similar data type.  Declaration: datatype *pointer_variable_name; 

Description : Develop a program to swap two numbers using pointer and add swaped numbers also print their addition.

Last Answer : #include<stdio.h> void swap(int *a,int *b) {  int temp;  temp=*a;  *a=*b;  *b=temp; } void main() { int x,y,sum; printf("\n Enter value for x:"); scanf(" ... x); printf("\ny=%d",y); sum=x+y; printf("Sum of x+y = %d",sum); }

Description : State any four math functions with its use. 

Last Answer : Math Functions: sqrt() - square root of an integer abs() - absolute value of an integer sin() - compute the sine value of an input value cos()- compute the cosine value of an input value pow() ... the power of a input value floor()- round down the input value ceil()- round up the input value

Description : State any four decision making statement.

Last Answer : Decision making statement: 1. if statement 2. if-else statement 3. if-else-if ladder 4. Nested if-else statement 5. switch statement 6. conditional operator statement (? : operator)

Description : State the Relational operators with example.

Last Answer : == - returns true if the values of two operands are equal else returns false. E.g: if (A= = B){ } != - returns true if values of two operands are not equal, else returns false E.g: if (A! = B ... the first operand is greater than or equal to the second, else returns false. E.g: if (A> = B){ }

Description : State the use of printf( ) & scanf( ) with suitable example.

Last Answer : printf( ) & scanf( ): printf() and scanf() functions are library functions in C programming language defined in stdio.h . printf() function is used to print the character, string, float, integer, octal and hexadecimal ... number"); scanf("%d",&i); printf("Entered number is: %d",i); getch(); }

Description : The first calculator that can perform all four arithmetic operations(Addition, Subtraction, Multiplication, Division) was known as______ (A) Pascaline (B) Slide Rule (C) Step Reckoner (D) None of the Above

Last Answer : (C) Step Reckoner

Description : Write a program which perform arithmetic operation using pointer.

Last Answer : #include<iostream.h> #include<conio.h> void main() { int num[5]={56,75,22,18,90}; int ptr; int i; cout<< array elements are:: ; for(i=0;i<5;i++) ptr=num; cout<< ... 3; cout<< value of ptr+=3:: <<*ptr; cout<< \n ; getch(); }

Description : Write a program to accept marks of four subjects as input from user. Calculate and display total and percentage marks of student. 

Last Answer : #include<stdio.h> #include<conio.h> void main() { float marks[4]; float total=0.0, perc=0.0; int i; clrscr(); for(i=1;i<=4;i++) { printf("Enter marks of ... is :%f",total); perc=total/4; printf("Percentage is %f",perc); getch(); }

Description : Explain any four library functions under conio.h header file.

Last Answer : clrscr() -This function is used to clear the output screen. getch() -It reads character from keyboard getche()-It reads character from keyboard and echoes to o/p screen putch - Writes ... function is used to change the text color textbackground()-This function is used to change text background

Description : Illustrate initialization of two dimensional array with example.

Last Answer : Two dimensional array: The array which is used to represent and store data in a tabular form is called as two dimensional array. Such type of array is specially used to represent data in a matrix form. ... where outer loop will increment row and inner loop will increment column. Eg : for(i=0;i

Description : Illustrate the use of break and continue statement with example.

Last Answer : Break: It breaks the execution of the loop which allows exiting from any loop or switch, such that break statement skips the remaining part of current iterations of the loop.  Syntax: ... then execution control will skip remaining statements of loop & will start next iteration of loop 

Description : List the categories of functions and explain any one with example.

Last Answer : Different categories of function: 1) Function with no arguments and no return value. 2) Function with arguments and no return value. 3) Function with no arguments and return value. 4) Function with ... have 4 and y will have 5 as their values and s will store value returned by the function.

Description : Explain nested if-else with example.

Last Answer : When a series of decision is required, nested if-else is used. Nesting means using one if-else construct within another one. If the condition in the outer if, is true, then only the inner if-else will get executed. ... } else { printf("Number is less than 5"); } getch(); }

Description : Explain strlen() and strcpy() function with example.

Last Answer : strlen()- this function is used to find the length of a string. It counts the number of characters comprising the string. Syntax: strlen(char[] str)- finds the length of the string str. Example: ... ; strcpy(dest,source); printf("\n%s %s",source, dest); getch(); }

Description : Explain conditional operator with example.

Last Answer : Conditional operators return one value if condition is true and returns another value is condition is false. This operator is also called as ternary operator as it takes three arguments. Syntax : (Condition? true_value: false_value) ... 0?printf("%d is even",i):printf("%d is odd",i) ; getch(); }

Description : Explain User defined function with example.

Last Answer : Functions are basic building blocks in a program. It can be predefined/ library functions or user defined functions. Predefined functions are those which are already available in C library. User defined functions are those which are ... value is: %d",a); } void main() { myFunc(10); getch() }

Description : Explain do-while loop with example. 

Last Answer : Do-While statement: In some applications it is necessary to execute the body of the loop before the condition is checked; such situation can be handled by do statement. At least once the body of loop will be executed ... till the value of i is less than or equal to 20 */ getch(); }

Description : Explain how formatted input can be obtain, give suitable example.

Last Answer : Formatted input: When the input data is arranged in a specific format, it is called formatted input. scanf function is used for this purpose in C. General syntax: scanf( control string , arg1, arg2..); Control ... number"); scanf("%d",&i); printf("Entered number is: %d",i); getch(); }

Description : Define type casting. Give any one example.

Last Answer : Definition type casting: The conversion of one data type to another is known as type casting. The values are changed for the respective calculation only, not for any permanent effect in a program. For ... sin((int)x) means x will be converted to integer and then sine angle will be calculated.  

Description : State the importance of flow chart. 

Last Answer : A flowchart is a type of diagram that represents an algorithm. It is a visual representation of a sequence of steps to complete the process. A flow chart describes a process using symbols rather ... to communicate a module's ultimate design, depending on the level of detail of the flowchart.

Description : State the syntax & use of strlen ( ) & strcat ( ) function.

Last Answer : strlen( ): calculates the length of the string Syntax: strlen(s1); strcat():concatenates two strings Syntax: strcat(s1,s2)

Description : State difference between array and string. 

Last Answer : Array String Array can be of any type like int, float, char.   String can contain only characters. Element Elements in an array can be accessed using its position like a[2]. ... . Array size once declared cannot be changed   String size can be modified using pointer.  

Description : State any two differences between while and do-while statement.  

Last Answer : while Do-while In 'while' loop the controlling condition appears at the start of the loop.  In 'do-while' loop the controlling condition appears at the end of the loop. The iterations ... is an exit controlled loop while(condition) { body }   do { body }while(condition);

Description : State use of while loop with syntax.

Last Answer : While loop is used in programming to repeat a specific block of statement until some end condition is met. The syntax of a while loop is: while (test Expression) {  Statements…  statements…. }

Description : The secondary storage devices can only store data but they cannot perform A) Arithmetic Operation B) Logic operation C) Fetch operations D) Either of the above

Last Answer : Answer : D

Description : The first machine to successfully perform a long series of arithmetic and logical operations was: A) ENIAC B) Mark-I C) Analytic Engine D) UNIVAC-1

Last Answer : Answer : B

Description : The secondary storage devices can only store data but they cannot perform a. Arithmetic Operation b. Logic operation c. Fetch operations d. Either of the above

Last Answer : Either of the above

Description : The first machine to successfully perform a long series of arithmetic and logical operations was; a. ENIAC b. Mark I c. Analytic engine d. UNIVAC-I

Last Answer : Mark

Description : The main function of the ALU is: a) Store Data and Information for Future Use b) Perform arithmetic and logical operations c) Control Computer Output, such as Printing d) None of These

Last Answer : b) Perform arithmetic and logical operations

Description : The main function of the ALU is to a) perform arithmetic and logical operations b) store data and information for future use c) control computer output, such as printing d) monitor all computer activities e) None of these

Last Answer : a) perform arithmetic and logical operations

Description : The first machine to successfully perform a long series of arithmetic and logical operations was: a. ENIAC b. Mark-I c. Analytic Engine d. UNIVAC-1

Last Answer : b. Mark-I

Description : The secondary storage devices can only store data but they cannot perform a. Arithmetic Operation b. Logic operation c. Fetch operations d. Either of the above

Last Answer : d. Either of the above

Description : The first machine to successfully perform a long series of arithmetic and logical operations was; a. ENIAC b. Mark I c. Analytic engine d. UNIVAC-I

Last Answer : b. Mark I

Description : The first machine to successfully perform a long series of arithmetic and logical operations was: a. ENIAC b. Mark-I c. Analytic Engine d. UNIVAC-1

Last Answer : b. Mark-I

Description : The secondary storage devices can only store data but they cannot perform a. Arithmetic Operation b. Logic operation c. Fetch operations d. Either of the above

Last Answer : d. Either of the above

Description : Which of the following is the most efficient to perform arithmetic operations on the numbers? (A) Sign-magnitude (B) 1’s complement (C) 2’s complement (D) 9’s complement

Last Answer : (C) 2’s complement

Description : Arithmetic and Logic Unit I. Perform Arithmetic operations II. Store Data III. Perform comparisons IV. Communicate with input devices Which of the following is true ? (1) I only (2) III only (3) I and II (4) I and III

Last Answer : I and III

Description : Calculate factorial of a number using recursion.

Last Answer : #include #include int factorial(int no) { if(no==1) return(1); else return(no*factorial(no-1)); } void main() { intfact,no; clrscr(); printf("\n Enter number"); scanf("%d",&no); fact=factorial(no); printf("\n Factorial number=%d",fact); getch(); }

Description : Write a function to print Fibonacci series starting from 0, 1.

Last Answer : void Fibbo() { inta,b,c,limit,i; printf("\n Enter number:"); scanf("%d",&limit); a=0; b=1; printf("%d\t%d",a,b); for(i=0;i

Description : Write a program to sort elements of an array in ascending order.

Last Answer : #include #include void main() { int a[5],i,j,temp; clrscr(); printf("\n Enter array elements:"); for(i=0;i

Description : Write a program to compute the sum of all elements stored in an array using pointers.

Last Answer : #include #include void main() { int a[5],sum=0,i,*ptr; clrscr(); printf("\n Enter array elements:"); for(i=0;i

Description : Write a program to calculate sum of all the odd numbers between 1 to 20.

Last Answer : Write a program to calculate sum of all odd element of 1D array

Description : Write a program to read two strings and find whether they are equal or not.

Last Answer : #include<stdio.h> #include<conio.h> #include<string.h> void main() { char st1[20],st2[20]; printf( enter string 1 ); scanf( %s ,st1); printf( enter second string ); ... 0) printf( \nboth strings are equal ); else printf( \nstrings are not equal ); }

Description : Write a program to add, subtract, multiply and divide two numbers, accepted from user switch case.

Last Answer : #include<stdio.h> #include<conio.h> void main() { int a,b,ch,add,sub,mul,div; clrscr(); printf("\n1 for addition \n2 for substraction"); printf("\n3 for multiplication \ ... break; default: printf("Invalid choice...."); } getch(); }