CrazyEngineers
  • c questions....

    neha1

    Member

    Updated: Oct 26, 2024
    Views: 1.4K
    1.Give explanation along with output:
    main()
    {
    int a[]={2.9,3.6,8,9.7,5.8};
    int j,*q=a;
    for(int i=0;j<5;j++)
    {
    printf("\t%d",*c);
    ++*q;
    }
    }

    2.
    main()
    {
    int i=-1;
    +i; //i dont know what does +i signify here,this is the only problem in this question
    printf("%d %d"i,+i);
    }

    3.
    main()
    {
    print("hiiiiiiii");
    main();
    }
    a.hiiiiiiii b.compiler error c.hiiiiiiii hiiiiiiiiiiiii hiiiiiiiiiiiiii............stack overflow d.undefined results

    4.printf("xy","ab","mn");
    it will print??
    a.xy b.xyabmn c.garbage value d.it will give error

    5.main()
    {
    printf(5+"intelligent");
    }

    6.main()
    {
    int a[5]={1,2,3,4,5};
    int *ptr=(int*)(&a+1);
    printf("%d %d",*(a+1),*(ptr-1));
    }
    a.2 2 b.2 5 c.2 1 d.none
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • techworm

    MemberJun 7, 2010

    neha1
    1.Give explanation along with output:
    main()
    {
    int a[]={2.9,3.6,8,9.7,5.8};
    int j,*q=a;
    for(int i=0;j<5;j++)
    {
    printf("\t%d",*c);
    ++*q;
    }
    }

    2.
    main()
    {
    int i=-1;
    +i; //i dont know what does +i signify here,this is the only problem in this question
    printf("%d %d"i,+i);
    }

    3.
    main()
    {
    print("hiiiiiiii");
    main();
    }
    a.hiiiiiiii b.compiler error c.hiiiiiiii hiiiiiiiiiiiii hiiiiiiiiiiiiii............stack overflow d.undefined results

    4.printf("xy","ab","mn");
    it will print??
    a.xy b.xyabmn c.garbage value d.it will give error

    5.main()
    {
    printf(5+"intelligent");
    }

    6.main()
    {
    int a[5]={1,2,3,4,5};
    int *ptr=(int*)(&a+1);
    printf("%d %d",*(a+1),*(ptr-1));
    }
    a.2 2 b.2 5 c.2 1 d.none
    1) in this question compiler will give 2 errors
    a) undefined variable c //if c is replaced by a it makes sense
    b)array of integers is assigned values in float

    2) here + is used as a unary operator

    3)compiler error print function undeclared
    if u correct this error then c is the correct ans

    4)here the output is "ligent"
    this syntax indicates that the output should print the string from 5th character counting from 0

    5)here ans is b)2,5
    for *(a+1) indicates a[0][1] which is 2 here.
    ptr contains the address of the memory location after the array..as it is (&a)+1...not &(a+1)..
    as ptr is an int pointer so ptr-1...indicates the location of the last element of the array..
    so *(ptr-1) is 5(the last element of the array)

    accordng to me these are the answers
    i hope you got all the ans..
    in case u have not...feel free to ask again😀
    Are you sure? This action cannot be undone.
    Cancel
  • ankesh.cs2007

    MemberJun 7, 2010

    hay neha nice set of questions.
    i agree with tech worm.
    he had forgot to answer q4
    ans is it will print xyabmn
    Are you sure? This action cannot be undone.
    Cancel
  • techworm

    MemberJun 8, 2010

    yeah...i missed that one....
    @ankesh but my compiler is giving the result as 'xy', even i cant understand the exact reason😕
    Are you sure? This action cannot be undone.
    Cancel
  • chaandsheikh

    MemberJun 8, 2010

    #include <windows.h>
    const char g_szClassName[] = "myWindowClass";
    // Step 4: the Window Procedure
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    switch(msg)
    {
    case WM_CLOSE:
    DestroyWindow(hwnd);
    break;
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    default:
    return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
    }
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
    {
    WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;
    //Step 1: Registering the Window Class
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = 0;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = g_szClassName;
    wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    if(!RegisterClassEx(&wc))
    {
    MessageBox(NULL, "Window Registration Failed!", "Error!",
    MB_ICONEXCLAMATION | MB_OK);
    return 0;
    }
    // Step 2: Creating the Window
    hwnd = CreateWindowEx(
    WS_EX_CLIENTEDGE,
    g_szClassName,
    "The title of my window",
    WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
    NULL, NULL, hInstance, NULL);
    if(hwnd == NULL)
    {
    MessageBox(NULL, "Window Creation Failed!", "Error!",
    MB_ICONEXCLAMATION | MB_OK);
    return 0;
    }
    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);
    // Step 3: The Message Loop
    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
    TranslateMessage(&Msg);
    DispatchMessage(&Msg);
    }
    return Msg.wParam;
    }




    Hi its Chaand from Nagpur
    The above is a simple windows program
    #-Link-Snipped-#
    I want a button in this window which will link to another window say the name of that button is Next
    Also How can i write some Text on that window which can be copied and paste say on notepad.
    Please Explain
    Are you sure? This action cannot be undone.
    Cancel
  • neha1

    MemberJun 8, 2010

    Hey......thanx Techworm....i got all the answers
    wel what about 4th question..??
    its output is xy only...why its so??please explain.....
    Are you sure? This action cannot be undone.
    Cancel
  • gaurav.bhorkar

    MemberJun 9, 2010

    neha1
    Hey......thanx Techworm....i got all the answers
    wel what about 4th question..??
    its output is xy only...why its so??please explain.....
    4.printf("xy","ab","mn");
    it will print??
    a.xy b.xyabmn c.garbage value d.it will give error
    The syntax of printf is

    printf ("<text> <%format_specifiers>", variable, variable....);

    If you say printf ("xy", "ab", "mn"), then only xy is printed because you haven't specified the format specifier. The first argument passed to printf contains format specifiers and text, while all other arguments correspond to the format specifiers.

    For example, the output of printf ("Crazy %d") would be "Crazy".
    whereas, the output of printf ("crazy %d", i) would be "Crazy <any integer>"

    Try putting printf ("xy %s %s", "ab", "mn"), the output will be "xy ab mn".

    You may argue that "ab" and "mn" aren't variables but strings. Ofcourse they are strings but, when passing arguments to a function always the base address of strings are passed not the whole string, and this base address is stored in a variable. So ultimately you are a passing a variable (base address).
    Are you sure? This action cannot be undone.
    Cancel
  • neha1

    MemberJun 9, 2010

    thanks gaurav...i do agree with you...
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register