Pointer C Questions 2012

6 comments Posted by Unknown at 19:39



1. What will be output when you will execute following c code?
#include<stdio.h>
void main(){
char arr[7]="Network";
printf("%s",arr);
}
Explanation:
Size of a character array should one greater than total number of characters in any string which it stores. In c every string has one terminating null character. This represents end of the string.So in the string “Network” , there are 8 characters and they are ‘N’,’e’,’t’,’w’,’o’,’r’,’k’ and ‘\0’. Size of array arr is seven. So array arr will store only first sevent characters and it will note store null character.
As we know %s in prinf statement prints stream of characters until it doesn’t get first null character. Since array arr has not stored any null character so it will print garbage value.

2.What will be output when you will execute following c code?
#include<stdio.h>
void main(){
    char arr[11]="The African Queen";
    printf("%s",arr);
}
Explanation:
Size of any character array cannot be less than the number of characters in any string which it has assigned. Size of an array can be equal (excluding null character) or greater than but never less than.

3.What will be output when you will execute following c code?
#include<stdio.h>
void main(){
    int const SIZE=5;
    int expr;
    double value[SIZE]={2.0,4.0,6.0,8.0,10.0};
    expr=1|2|3|4;
    printf("%f",value[expr]);
}
Explanation:
Size of any array in c cannot be constantan variable.

4.What will be output when you will execute following c code?
#include<stdio.h>
enum power{
    Dalai,
    Vladimir=3,
    Barack,
    Hillary
};
void main(){
    float leader[Dalai+Hillary]={1.f,2.f,3.f,4.f,5.f};
    enum power p=Barack;
    printf("%0.f",leader[p>>1+1]);
}
Explanation:
Size of an array can be enum constantan.
Value of enum constant Barack will equal to Vladimir + 1 = 3 +1 = 4
So, value of enum variable p  = 4
leader[p >> 1 +1]
= leader[4 >> 1+1]
=leader[4 >> 2]   //+ operator enjoy higher precedence than >> operator.
=leader[1]  //4>>2 = (4 / (2^2) = 4/4 = 1
=2

5.What will be output when you will execute following c code?
#include<stdio.h>
#define var 3
void main(){
    char *cricket[var+~0]={"clarke","kallis"};
    char *ptr=cricket[1+~0];
    printf("%c",*++ptr);
}
Explanation:
In the expression of size of an array can have micro constant.
var +~0 = 3 + ~0 = 3 + (-1)  = 2
Let’s assume string “clarke” and “kallis” has stored at memory address 100 and 500 respectively as shown in the following figure:
For string “clarke”:
For string “kallis”:
In this program cricket is array of character’s pointer of size 2. So array cricket will keep the memory address of first character of both strings i.e. content of array cricket is:
cricket[2] = {100,500}
ptr is character pointer which is pointing to the fist element of array cricket. So, ptr = 100
Now consider on *++ptr
Since ptr = 100 so after ++ptr , ptr = 101
*(++ptr) = *(101) = content of memory address 101. From above figure it is clear that character is l.

6.What will be output when you will execute following c code?
#include<stdio.h>
void main(){
    char data[2][3][2]={0,1,2,3,4,5,6,7,8,9,10,11};
    printf("%o",data[0][2][1]);
}
Explanation:
%o in printf statement is used to print number in the octal format.

7.What will be output when you will execute following c code?
#include<stdio.h>
void main(){
    short num[3][2]={3,6,9,12,15,18};
    printf("%d  %d",*(num+1)[1],**(num+2));
}
Explanation:
*(num+1)[1]=*(*((num+1)+1))=*(*(num+2))=*(num[2])=num[2][0]=15And**(num+2)=*(num[2]+0)=num[2][0]=15
8.What will be output when you will execute following c code?
#include<stdio.h>
void main(){
    char *ptr="cquestionbank";
    printf("%d",-3[ptr]);
}
Explanation:
-3[ptr]=-*(3+ptr)=-*(ptr+3)
=-ptr[3]
=-103  //ASCII value of character ‘e’ is 103

9.What will be output when you will execute following c code?
#include<stdio.h>
void main(){
    long  myarr[2][4]={0l,1l,2l,3l,4l,5l,6l,7l};
    printf("%ld\t",myarr[1][2]);
    printf("%ld%ld\t",*(myarr[1]+3),3[myarr[1]]);
    printf("%ld%ld%ld\t" ,*(*(myarr+1)+2),*(1[myarr]+2),3[1[myarr]]);  
}
Explanation:
Think yourself.

10.What will be output when you will execute following c code?
#include<stdio.h>
void main(){
    int array[2][3]={5,10,15,20,25,30};
    int (*ptr)[2][3]=&array;
    printf("%d\t",***ptr);
    printf("%d\t",***(ptr+1));
    printf("%d\t",**(*ptr+1));
    printf("%d\t",*(*(*ptr+1)+2));
}
Explanation:
ptr is pointer to two dimension array.
***ptr
=***&array  //ptr = &array
=**array //* and & always cancel to each other
=*arr[0]  // *array = *(array +0) = array[0]
=array[0][0]
= 5
Rests think yourself.

11.What will be output when you will execute following c code?
#include<stdio.h>
void main(){
    static int a=2,b=4,c=8;
    static int *arr1[2]={&a,&b};
    static int *arr2[2]={&b,&c};
    int* (*arr[2])[2]={&arr1,&arr2};
    printf("%d %d\t",*(*arr[0])[1],  *(*(**(arr+1)+1)));
}
Explanation:
Consider on the following expression:
*(*arr[0])[1]
=*(*&arr1)[1]  //arr[0] = &arr1
=*arr1[1]   //* and & always cancel to each other
=*&b
=b
=4
Consider on following expression:
*(*(**(arr+1)+1))
= *(*(*arr[1]+1))  //*(arr+1) = arr[1]
= *(*(*&arr2+1))  //arr[1] = &arr2
=*(*(arr2+1))  //*&arr2 = arr2
=*(arr2[1])  //*(arr2+1) = arr2[1]
=  *&c    //arr2[1] = &c
=  c
= 8

12.What will be output when you will execute following c code?
#include<stdio.h>
#include<math.h>
double myfun(double);
void main(){
    double(*array[3])(double);
    array[0]=exp;
    array[1]=sqrt;
    array[2]=myfun;
    printf("%.1f\t",(*array)((*array[2])((**(array+1))(4))));  
}
double myfun(double d){
       d-=1;
       return d;
}
Explanation:
array is array of pointer to such function which parameter is double type data and return type is double.
Consider on following expression:
(*array)((*array[2])((**(array+1))(4)))
= (*array)((*array[2])((*array[1])(4)))
//*(array+1) = array[1]
= (*array)((*array[2])(sqrt(4))))
//array[1] = address of sqrt function
= (*array)((*array[2])(2.000000)))
= (*array)(myfun(2.000000)))
// array[2] = address of myfunc function
=(*array)(1.000000)
=array[0](1.000000)
=exp(1.000000)

13.What will be output when you will execute following c code?
#include<stdio.h>
typedef struct{
    char *name;
    double salary;
}job;
void main(){
    static job a={"TCS",15000.0};
    static job b={"IBM",25000.0};
    static job c={"Google",35000.0};
    int x=5;
    job * arr[3]={&a,&b,&c};
    printf("%s  %f\t",(3,x>>5-4)[*arr]);
}
double myfun(double d){
       d-=1;
       return d;
}
Explanation:
(3,5>>5-4)[*arr]
=(3,5>>5-4)[*arr] //x=5
= (3,5>>1)[*arr] //- operator enjoy higher precedence than >>
= (3,2)[*arr]  //5>>1 = 5/(2^1) = 5 /2 = 2
= 2[*arr]  //In c comma is also operator.
= *(2 + *arr)
= *(*arr + 2)
=*arr[2]
=*(&c) //arr[2] = &c
=c   // *  and & always cancel to each other.
So,
printf("%s  %f\t",c);
=> printf("%s  %f\t", "Google",35000.0);

14.What will be output when you will execute following c code?
#include<stdio.h>
union group{
    char xarr[2][2];
    char yarr[4];
};
void main(){
    union group x={'A','B','C','D'};
    printf("%c",x.xarr[x.yarr[2]-67][x.yarr[3]-67]);
}
Explanation:
In union all member variables share common memory space.
So union member variable, array xarray will look like:
{
{‘A’,’B’},
{‘C’,’D’}
}
And union member variable, array yarray will look like:
{
{‘A’,’B’,’C’,’D’}
}
x.xarr[x.yarr[2]-67][x.yarr[3]-67]
= x.xarr[‘C’-67][‘D’-67]
= x.xarr[67-67][68-67]
//ASCII value of ‘C’ is 67 and ‘D’ is 68.
x.xarr[0][1]
=’B’

15.What will be output when you will execute following c code?
#include<stdio.h>
void main(){
    int a=5,b=10,c=15;
    int *arr[3]={&a,&b,&c};
    printf("%d",*arr[*arr[1]-8]);
}
Explanation:
Member of an array cannot be address of auto variable because array gets memory at load time while auto variable gets memory at run time.
16.What will be output when you will execute following c code?
#include<stdio.h>
void main(){
    int arr[][3]={{1,2},{3,4,5},{5}};
    printf("%d %d %d",sizeof(arr),arr[0][2],arr[1][2]);
}
Explanation:
If we will not write size of first member of any array at the time of declaration then size of the first dimension is max elements in the initialization of array of that dimension.
So, size of first dimension in above question is 3.
So size of array = (size of int) * (total number of elements) = 2 *(3*3) = 18
Default initial value of rest elements are zero.  So above array will look like:
{
{1,2,0}
{3,4,5},
{5,0,0}
}        

17.What will be output when you will execute following c code?
#include<stdio.h>
void main(){
    int xxx[10]={5};
    printf("%d %d",xxx[1],xxx[9]);
}
Explanation:
If we initialize any array at the time of declaration the compiler will treat such array as static variable and its default value of uninitialized member is zero.

18.What will be output when you will execute following c code?
#include<stdio.h>
#define WWW -1
enum {cat,rat};
void main(){
    int Dhoni[]={2,'b',0x3,01001,'\x1d','\111',rat,WWW};
    int i;
    for(i=0;i<8;i++)
         printf(" %d",Dhoni[i]);
}
Explanation:
Dhoni[0]=2
Dhoni[1]=’b’ =98  //ASCII value of character ‘b’ is 98.
Dhoni[2]=  0x3  =  3  //0x represents hexadecimal number. Decimal value of hexadecimal 3 is also 3.
Dhoni[3]=01001 = 513 //Number begins with 0 represents octal number.
Dhoni[4]  = ‘\x1d’ = 29 //’\x1d’ is hexadecimal character constant.
Dhoni[5] = ‘\111’ = 73 //’\111’ is octal character constant.
Dhoni[6] =rat = 1  //rat is enum constant
Dhoni[7] = WWW = -1  //WWW is macro constant.

19.What will be output when you will execute following c code?
#include<stdio.h>
void main(){
    long double a;
    signed char b;
    int arr[sizeof(!a+b)];
    printf("%d",sizeof(arr));
}
Explanation:
Size of data type in TURBO C 3.0 compiler is:
S.N.
Data type
Size(In byte)
1
char
1
2
int
2
3
double
8
Consider on the expression: !a + b
! Operator always return zero if a is non-zero number other wisie 1. In general we can say ! operator always returns an int type number. So
!a +b
=! (Any double type number) + Any character type number
= Any integer type number + any character type number
= Any integer type number
Note: In any expression lower type data is always automatically type casted into the higher data type. In this case char data type is automatically type casted into the int type data.
So sizeof (!a +b) = sizeof(Any int type number)  = 2
So size of array arr is 2 and its data type is int. So
sizeof(arr) = size of array * sizeof its data type = 2* 2= 4
20.What will be output when you will execute following c code?
#include<stdio.h>
void main(){
    char array[]="Ashfaq \0 Kayani";
    char *str="Ashfaq \0 Kayani";
    printf("%s %c\n",array,array[2]);
    printf("%s %c\n",str,str[2]);
    printf("%d %d\n",sizeof(array),sizeof(str));
}
Explanation:
A character array keeps the each element of an assigned array but a character pointer always keeps the memory address of first element.
As we know %s in prints the characters of stream until it doesn’t any null character (‘\0’).  So first and second printf function will print same thing in the above program.  But size of array is total numbers of its elements i.e. 16 byte (including ending null character). While size of any type of pointer is 2 byte (near pointer).
Read More »

C Language Quiz 2012

17 comments Posted by Unknown at 18:28

Quiz 2012 C Quiz


#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

{

int i=5;

clrscr();

printf("\t%d\t %d \t %d\t%d",++i,i,i--,i);

getch();

}

Read More »

Interview Wishes

1 comments Posted by Unknown at 20:38

Job Interview Wishes







You dreamed, you believed and you worked. Now, go achieve it. Good Luck.


Read More »

interview Logos

0 comments Posted by Unknown at 19:36


Read More »

Kareena Kapoor interview

2 comments Posted by Unknown at 18:45

Kareena Kapoor Interview



Read More »

Anushka Interview

0 comments Posted by Unknown at 18:33

Anushka Interview on Asianet 




Anushka Interview on Asianet -Sweet Talk Part 1




Read More »

Angelina Jolie interview

0 comments Posted by Unknown at 18:23

Angelina Jolie Interview 2012 



Read More »

Namitha Interview

0 comments Posted by Unknown at 18:12

 Namitha Interview - Part 1




Read More »

Top 10 Interview Tips

0 comments Posted by Unknown at 17:54

Top 10 Interview Tips (Part 1)





Read More »

Tough Interview Questions Videos

0 comments Posted by Unknown at 17:51


Tell Me About Yourself




Read More »

Defining class and object

0 comments Posted by Unknown at 19:01

class students
{
        private int sno;
        private String sname;
        public void setstud(int no,String name)
        {
                sno = no;
                sname = name;
        }
        public void dispstud()
        {
                System.out.println("Student No : " + sno);
                System.out.println("Student Name :" + sname);
        }
        public static void main(String args[])
        {
                if(args.length < 2)
                {
                        System.out.println("Invalid Arguments");
                        System.exit(0);
                }
                students s = new students();
                int no = Integer.parseInt(args[0]);
                String name = args[1];
                s.setstud(no,name);
                s.dispstud();
        }
}
Read More »

Passing arguments and returning values.

0 comments Posted by Unknown at 19:01

Passing arguments and returning values.
class circle
{
        private int radius;
        public void setradius(int r)
        {
                radius = r;
        }
        public float calculate()
        {
                return 3.14f * radius * radius;
        }
        public static void main(String args[])
        {
                if (args.length < 1)
                {
                        System.out.println("Invalid Arguments");
                        System.exit(0);
                }
                circle c = new circle();
                c.setradius(Integer.parseInt(args[0]));
                float area = c.calculate();
                System.out.println("Radius : " + args[0]);
                System.out.println("Area : " + area);
        }
}
Read More »

Passing object as arguments.

1 comments Posted by Unknown at 19:01

class rectangle
{
        private int len,bre;
        public void setrect(int l,int b)
        {
                len = l;
                bre = b;
        }
        public int totlen(rectangle t)
        {
                return len + t.len;
        }
        public int totbre(rectangle t)
        {
                return bre + t.bre;
        }
        rectangle combine(rectangle t)
        {
                rectangle temp = new rectangle();
                temp.len = len + t.len;
                temp.bre = bre + t.bre;
                return temp;
        }
        public void disp()
        {
                System.out.println("Length : " + len + "\t Breadth : " + bre);
        }
        public static void main(String args[])
        {
                rectangle r1 = new rectangle();
                rectangle r2 = new rectangle();
                rectangle r3 = new rectangle();
                r1.setrect(2,3);
                r2.setrect(4,5);
                int tlen = r1.totlen(r2);
                int tbre = r1.totbre(r2);
                r3 = r1.combine(r2);
                System.out.println("Total length : " + tlen);
                System.out.println("Total Breadth : " + tbre);
                r1.disp();
                r2.disp();
                r3.disp();
        }
}
Read More »

Function overloading

0 comments Posted by Unknown at 19:00

class exam
{
        private int m1,m2,total;
        public void setmarks(int ma1,int ma2)
        {
                m1 = ma1;
                m2 = ma2;     
        }
        public void setmarks()
        {
                m1 = 80;
                m2 = 100;
        }
        void calculate()
        {
                total = m1 + m2;
        }
        void disp()
        {
                System.out.println("Mark1 : " + m1 + "\t Mark2 " + m2 + "\t Total " + total);
        }
        public static void main(String args[])
        {
                exam e1 = new exam();
                exam e2 = new exam();
                e1.setmarks();
                e2.setmarks(70,80);
                e1.calculate();
                e2.calculate();
                e1.disp();
                e2.disp();
        }
}
Read More »

Static Variables and Methods

0 comments Posted by Unknown at 18:59

class Rect
{
        int length;
        int breadth;
        int area;
        static int count;
        Rect(int a,int b)
        {
                length = a;
                breadth = b;
                count++;
        }
        Rect()
        {
                length = 0;
                breadth = 0;
                count++;
        }
        void calc()
        {
                area = length * breadth;
        }
        void display()
        {
                System.out.println("Length : " + length);
                System.out.println("Breadth : " + breadth);
                System.out.println("Area : " + area);
        }
}
class Rect1
{
        public static void main(String args[])
        {
                System.out.println("No of object : " + Rect.count);
                Rect r1 = new Rect(10,20);
                r1.calc();
                System.out.println("No of object : " + Rect.count);
                Rect r2 = new Rect();
                r2.calc();
                System.out.println("No of object : " + Rect.count);
                r1.display();
                r2.display();
        }
}
Read More »

The Job Interview Phrase Book: The Things to Say to Get You the Job You Want

0 comments Posted by Unknown at 18:09

      • Author:  Nancy Schuman
      • File Size: 364 KB
      • Print Length: 258 pages
      • Page Numbers Source ISBN: 144050184X
      • Publisher: Adams Media (October 18, 2009)
      • Sold by: Amazon Digital Services, Inc.
      • Language: English
      • ASIN: B002SV379U
Read More »

Knockout Interview Answers (52 Brilliant Ideas)

0 comments Posted by Unknown at 17:40

    • Paperback: 272 pages
    • Publisher: Infinite Ideas; 2nd edition (March 1, 2007)
    • Language: English
    • ISBN-10: 1904902979
    • ISBN-13: 978-1904902973
    • Product Dimensions: 8.2 x 6.8 x 0.9 inches

Read More »

100 Interview Tips

0 comments Posted by Unknown at 17:06

  • Size: 370.8KB
  • Version: 1.0
  • Developed By: KoolAppz

Read More »

High-Impact Interview Questions: 701 Behavior-Based Questions to Find the Right Person for Every Job

0 comments Posted by Unknown at 16:43

  • Author: Victoria A. Hoevemeyer
  • Paperback: 192 pages
  • Publisher: AMACOM; 1 edition (September 26, 2005)
  • Language: English
  • ISBN-10: 0814473016
  • ISBN-13: 978-0814473016
  • Product Dimensions: 6 x 0.7 x 9 inches
Read More »

Hibernate, Spring & Struts Interview Questions You'll Most Likely Be Asked

0 comments Posted by Unknown at 16:19

  • Author: Vibrant Publishers
  • Paperback: 116 pages
  • Publisher: CreateSpace (January 14, 2011)
  • Language: English
  • ISBN-10: 1456518380
  • ISBN-13: 978-1456518387

Read More »

C & C++ Interview Questions You'll Most Likely Be Asked

0 comments Posted by Unknown at 16:05

Author: Vibrant Publishers
  • Paperback: 128 pages
  • Publisher: CreateSpace (July 15, 2010)
  • Language: English
  • ISBN-10: 1453709665
  • ISBN-13: 978-1453709665

Read More »

XML Interview Questions, Answers, and Explanations: XML Certification Review

0 comments Posted by Unknown at 15:56

  • Author: Jamie Fisher
    File Size: 155 KB
  • Print Length: 77 pages
  • Simultaneous Device Usage: Unlimited
  • Sold by: Amazon Digital Services, Inc.
  • Language: English
  • ASIN: B003X27PO6

Read More »

Ace Your Teacher Interview: 149 Fantastic Answers to Tough Interview Questions

0 comments Posted by Unknown at 18:43

  • Author:Anthony D. Fredericks
    Paperback: 224 pages
  • Publisher: Jist Works (January 1, 2012)
  • Language: English
  • ISBN-10: 1593578660
  • ISBN-13: 978-1593578664
  • Product Dimensions: 9.2 x 6.2 x 0.6 inches



Description:
An all-in-one sourcebook of teacher interview questions in concert with the best responses to the questions most frequently asked of aspiring educators. Ace Your Teacher Interview offers specific questions and responses gathered from dozens of principals and administrators across the country, along with a creative range of inside information on what impresses interview committees. This book is designed to provide readers with practical and realistic advice that informs and illustrates without being dogmatic or professorial. Teachers and college students majoring in education as well as people entering teaching from other professions will find this book a valuable resource.

Download Lnks:
Read More »

Ace the IT Interview

0 comments Posted by Unknown at 18:39

  • Author:Paula Moreira
  • Paperback: 296 pages
  • Publisher: McGraw-Hill Osborne Media; 2 edition (December 11, 2007)
  • Language: English
  • ISBN-10: 0071495789
  • ISBN-13: 978-0071495783
  • Product Dimensions: 8 x 0.6 x 10 inches



Description
This practical guide for developing winning interviewing skills has been fully updated and revised to focus on today's most sought-after IT jobs. Go behind the scenes of the IT interview process and get inside the mind of potential employers. You'll find out how to make a great first impression and stand out from the competition. Ace the IT Interview features hundreds of questions that are likely to come up on your next technical interview along with key points to include in your answers so you can practice your responses based on your strengths and experience. Present yourself as a truly valuable IT professional and get a great job with help from this real-world guide.

Download Links
Read More »

XML Interview Questions You'll Most Likely Be Asked (Job Interview Questions Series)

0 comments Posted by Unknown at 17:58

  • Author : Vibrant Publishers
    Paperback: 102 pages
  • Publisher: CreateSpace (March 14, 2011)
  • Language: English
  • ISBN-10: 145648236X
  • ISBN-13: 978-1456482367
  • Product Dimensions: 5.5 x 8.5 x 0.2 inches

Description

XML Interview Questions You'll Most Likely Be Asked is a perfect companion to stand ahead above the rest in today’s competitive job market. Rather than going through comprehensive, textbook-sized reference guides, this book includes only the information required immediately for job search to build an IT career. This book puts the interviewee in the driver's seat and helps them steer their way to impress the interviewer. Includes: a) 200 XML Interview Questions, Answers and Proven Strategies for getting hired as an IT professional b) Dozens of examples to respond to interview questions c) 51 HR Questions with Answers and Proven strategies to give specific, impressive, answers that help nail the interviews d) 2 Aptitude Tests download available on www.vibrantpublishers.com


Download Links:
Read More »
 

© 2011. All Rights Reserved | Interview Questions | Template by Blogger Widgets

Home | About | Top