-->

college terminal questions

Please click the given  link.
-----------------------------------------------------------------------------
for 11(science+mgmt):

click for main content(folder)

or
1)click for 2072 B.S. questions

2) click for 2073 B.S. questions

3) click for 2074 B.S. questions

4) click for 2075 B.S. questions


--------------------------------------------
for 12(management only):

click for main content(folder)
or
--------------------------------------
1)click for 2072 B.S. questions

2) click for 2073 B.S. questions

3) click for 2074 B.S. questions

4) click for 2075 B.S. questions



program to understand malloc() using struct

//understanding struct pointer
#include <stdio.h>
#include <stdlib.h>
struct reco
{
    int a;
    float b;
    char c;
};
int main()
{
    struct reco *p;//pointer declaration of struct type
    p=(struct reco *) malloc (sizeof(struct reco));//memory allocation
    p->a=10;//value assignment
    p->b=3.14;//value assignment
    p->c='a';//value assignment
    printf("i=%d \nf=%f\nc= %c\n",(*p).a,(*p).b,(*p).c);//value printing
    free(p);
    return 0;
}

to understand free() function

//understanding free()
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int *x ;//pointer declaration
    x= (int*)malloc(10*sizeof(int));//allocates the memory for 10 integers(10x4=40)
                                    // to heap

    if(x==NULL)//tests whether the memory is available
    {
        printf("error in allocating");//displays error if no memory
    }
    else
    {
    printf("%d\n", sizeof(x));//prints value 4. Because the
                            //sizeof thinks what memory each value/integer will occupy
    }
    free(x);//frees the memory.
    return 0;
}

understanding malloc()

//understanding malloc()
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int *x ;//pointer declaration
    x= (int*)malloc(10*sizeof(int));//allocates the memory for 10 integers(10x4=40)
                                    // to heap

    if(x==NULL)//tests whether the memory is available
    {
        printf("error in allocating");//displays error if no memory
    }
    else
    {
    printf("%d\n", sizeof(x));//prints value 4. Because the
                            //sizeof thinks what memory each value/integer will occupy
    }
    return 0;
}

off topics tips/tricks

1) understanding about malloc() function:

                                                                                                                    solution

                                                                                                                    solution


2)to understand free() function

                                                                                                                  solution

3)WAP to understand malloc() using struct pointer.

                                                                                                                   solution

                                                                                                                   solution

program to understand about malloc() function

//understanding malloc()
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int *x ;
    x= (int*)malloc(sizeof(int));//allocates the memory(4 bytes) to heap
    if(x==NULL)//tests whether the memory is available
    {
        printf("error in allocating");//displays error if no memory
    }
    else
    {
        *x=10;//assigns value
    printf("%d\n", *x);//prints value 10
    }
    return 0;
}

WAP to input a string and to print its address(character's) with its value.

//progrm to print address and value of a string given by user.
#include <stdio.h>
int main()
{
    char name[30];
    char *p;
    int i=0;
    printf("enter the string\n");
    scanf("%s",name);
    p=name;//assigning base address
    while(*p!='\0')//condition testing
    {
    printf("the address=%d and value=%c\n",p+i,*p);//printing value and address
   *p++;//changing the value
    i++;//changing the value of i
    }
 

    return 0;
}