What is the difference between exit(0) and exit(1)? Discuss the need of nested structue with an example. Write a program to find the value of xy without using POW code.

This answer is restricted. Please login to view the answer of this question.

Login Now

The difference between exit(0) and exit(1) are

exit(0) exit(1)
Reports the successful termination/completion of the program. Reports the abnormal termination of the program.
Reports the termination when the program gets executed without any error. Reports the termination when some error or interruption occurs during the execution of the program.
The syntax is exit(0); The syntax is exit(1);
The use of exit(0) is fully portable. The use of exit(1) is not portable.
The macro used for return code 0 is EXIT_SUCCESS The macro used for return code 1 is EXIT_FAILURE
EXIT_SUCCESS is defined by the standard to be zero. EXIT_FAILURE is not restricted by the standard to be one, but many systems do implement it as one.

Nested Structure in c:

C provides us the feature of nesting one structure within another structure by using which, complex data types are created. For example, we may need to store the address of an entity employee in a structure. The attribute address may also have the subparts as street number, city, state, and pin code. Hence, to store the address of the employee, we need to store the address of the employee in a separate structure and nest the structure address into the structure employee. Consider the following program.

#include<stdio.h>  
struct address   
{  
    char city[20];  
    int pin;  
    char phone[14];  
};  
struct employee  
{  
    char name[20];  
    struct address add;  
};  
void main ()  
{  
    struct employee emp;  
    printf("Enter employee information?\n");  
    scanf("%s %s %d %s",emp.name,emp.add.city, &emp.add.pin, emp.add.phone);  
    printf("Printing the employee information....\n");  
    printf("name: %s\nCity: %s\nPincode: %d\nPhone: %s",emp.name,emp.add.city,emp.add.pin,emp.add.phone);  
}

The output of above program is

Enter employee information?

Arun            

Delhi           

110001       

1234567890    

Printing the employee information....   

name: Arun      

City: Delhi  

Pincode: 110001

Phone: 1234567890

Program to find the value of xy without using the POW function.

#include <stdio.h>

int Pow(int X, int Y) {

    int power = 1, i;

    for (i = 1; i <= Y; ++i) {
        power = power * X;
    }

    return power;

}

int main() {

    long long int base, exponent;

    printf("Enter Base: ");
    scanf("%d", &base);

    printf("Enter Power: ");
    scanf("%d", &exponent);

    printf("%d ^ %d = %d", base, exponent, Pow(base, exponent));
        return 0;
}

The output of the above program is

Enter Base: 5
Enter Power: 3
5 ^ 3 = 125
If you found any type of error on the answer then please mention on the comment or report an answer or submit your new answer.
Leave your Answer:

Click here to submit your answer.

Discussion
0 Comments
  Loading . . .